Welcome to the Cookbook

loading...

7.1.2.4 form

form(string $action, string $type, array $options)

Returns a form tag that submits to $action using XMLHttpRequest instead of a normal HTTP request via $type ('post' or 'get'). Otherwise, form submission will behave exactly like normal: data submitted is available at $this->data inside your controllers. If $options['update'] is specified, it will be updated with the resulting document. Callbacks can be used.

The options array should include the model name e.g.
$ajax->form('edit','post',array('model'=>'User','update'=>'UserInfoDiv'));
  1. $ajax->form('edit','post',array('model'=>'User','update'=>'UserInfoDiv'));
Alternatively, if you need to cross post to another controller from your form:
$ajax->form(array('type' => 'post',
    'options' => array(
        'model'=>'User',
        'update'=>'UserInfoDiv',
        'url' => array(
            'controller' => 'comments',
            'action' => 'edit'
        )
    )
));
  1. $ajax->form(array('type' => 'post',
  2. 'options' => array(
  3. 'model'=>'User',
  4. 'update'=>'UserInfoDiv',
  5. 'url' => array(
  6. 'controller' => 'comments',
  7. 'action' => 'edit'
  8. )
  9. )
  10. ));

You should not use the $ajax->form() and $ajax->submit() in the same form. If you want the form validation to work properly use the $ajax->submit() method as shown below.