/** * Observe entire form and call ajax on change. * * Like @see observeField(), but operates on an entire form identified by the * DOM ID <b>form</b>. <b>options</b> are the same as <b>observeField</b>, except * the default value of the <i>with</i> option evaluates to the * serialized (request string) value of the form. * * @param string $form DOM ID of form to observe * @param array $options ajax options * @return string ajax script */ function observeForm($form, $options = array()) { if (!isset($options['with'])) { $options['with'] = "$('#$form').serialize()"; } $callback = $this->remoteFunction($options); return $this->Javascript->event("'#{$form} input, #{$form} select, #{$form} textarea'", "change", $callback); }
/** * Returns a button input tag that will submit using Ajax * * Returns a button input tag that will submit form using XMLHttpRequest in the background instead * of regular reloading POST arrangement. <i>options</i> argument is the same as * in AjaxHelper::form(). * * @param string $title Input button title * @param array $options Callback options * @return string Ajaxed input button * @see AjaxHelper::form() * @link http://book.cakephp.org/1.3/en/The-Manual/Core-Helpers/AJAX.html#submit */ function submit($title = 'Submit', $options = array()) { $htmlOptions = $this->__getHtmlOptions($options); $htmlOptions['value'] = $title; if (!isset($options['with'])) { $options['with'] = 'Form.serialize(Event.element(event).form)'; } if (!isset($htmlOptions['id'])) { $htmlOptions['id'] = 'submit' . intval(mt_rand()); } $htmlOptions['onclick'] = "event.returnValue = false; return false;"; $callback = $this->remoteFunction($options); $form = $this->Form->submit($title, $htmlOptions); $script = $this->Javascript->event('"' . $htmlOptions['id'] . '"', 'click', $callback); return $form . $script; }