ajax and validation, the Beginner example

Hello,
i trid to get lucky with very first, the GuiControls example.
i have noticed that the ajax droplist fetching feature doesn't work. What is being inserted into the div is the whole page.
i made my own investigation on this. i found out that the ajax POST query contains form's data and those are being non-validated because the user had only started to fill the form. And therefore ajax gets the whole page as redirected reply.
ok i made the variuable $validate_needed in the guicontrols_component that cpmpares the form URL ( in session ) and VIRTUAL_URL. And, made the following vaildating code block conditionally dependable to execute on it. So the redirect on the incorrect submission works as well as div inhabitance with ajax.
i can submit such the patch but think it's my fault of insufficient knowledge on controls validaion. There should be another way to get this thing made, isn't it?

AJAX

Can you post your template code? in particular, the code that makes the AJAX request? Usually, you can have AJAX post only the data necessary for your form, thus bypassing the guicontrols validation. However, we may also be interested in your solution. It looks like your code was stripped. If you could repost it, that would be helpful.

john 18 Nov 2008

validation and submit_onchange

Those are the parts of code from the the skeleton attached to 1.5.0, same as for this site at the Doc-Beginner-guiControls:

   $select_update = &getGuiControl('select_update', 'select_update');
    $select_update->setParam('index', array('optionA' => 'optionA', 'optionB' => 'optionB'));
    $select_update->setParam('url', SCRIPT_URL . "/SelectUpdateList");
    $select_update->setParam('method', "POST");
  function postSelectUpdateList($inPath)    // This function is called using ajax to populate a div in the pageGuiControlExample.
  {
    $newselectupdate = &getGuiControl('select', 'dynamically created select control');
    $newselectupdate->setParam('index', array('optionC' => 'optionC', 'optionD' => 'optionD'));
    $newselectupdate->display();
  }

i look at the html form code and see that the whole form is being posted on select's onChange. Ok, but the form is not yet fully filled with required inputs! And thus instead of droplist of C and D the div gets to insert the redirected pageDefault.
Here is what I have done. In guicontrol_component:init :

    $GLOBALS['controlData'] = NULL;
    $GLOBALS['controls'] = NULL;
    $validate_needed = 1;
    if($_SERVER["REQUEST_METHOD"] == 'POST')
    {
      $post = getRawPost();
 
      if(isset($post['controls']))
      {
        $GLOBALS['controlData'] = $post["controls"];
        UnsetPost('controls');
      }
      if( isset( $_SESSION['guiControlUrl'] ) )
      {
        $validate_needed = ( $_SESSION['guiControlUrl'] == VIRTUAL_URL );
      }
    }

i established the validate_neede variable and use it to distinguish if controller's action differs from regular form post:

    if( isset($controlData)
        &&
        $validate_needed
      ){
      $validate = true;

i include the _needed variable into the condition.
It works ( as both the submit_onchange and validation ) for that example, but may not for others.

petr999 18 Nov 2008

any news on this?

do you plan to incoparate this change on the next version of the framework? If so let us know what to use (how to patch the framework) to be future-compatible

thanks,
Alex

alexan 01 Dec 2008