Created
March 30, 2015 18:08
-
-
Save doublejosh/2b50a9b17a851d2060a6 to your computer and use it in GitHub Desktop.
Ajaxify
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function my_module_special_form($form, &$form_state, $node = FALSE) { | |
| $node_id = (is_object($node) && is_numeric($node->nid)) ? $node->nid : ''; | |
| // Ajaxify. | |
| if (module_exists('context') && _tableau_is_active_context(array('ajaxify_premium')) {) | |
| $form['#prefix'] = '<div id="formwrapper">'; | |
| $form['#suffix'] = '</div>'; | |
| // Submit button. | |
| $form['save']['#ajax'] = array( | |
| 'callback' => 'my_module_special_form_ajax_submit', | |
| 'wrapper' => 'formwrapper', | |
| 'method' => 'replace', | |
| 'effect' => 'fade', | |
| ); | |
| /* | |
| $form['submit'] = array( | |
| '#ajax' => array( | |
| 'callback' => 'my_module_special_form_submit', | |
| 'wrapper' => 'form-register-message' | |
| ), | |
| ); | |
| */ | |
| } | |
| /** | |
| * Accept the form submit via AJAX. | |
| * | |
| * @param [type] $form [description] | |
| * @param [type] &$form_state [description] | |
| * | |
| * @return [string] | |
| * HTML output back to the browser. | |
| */ | |
| function my_module_special_form_ajax_submit($form, &$form_state) { | |
| // Be sure to validate. | |
| drupal_validate_form('my_module_special', $form, $form_state); | |
| if (form_get_errors()) { | |
| $form_state['rebuild'] = TRUE; | |
| return $form; | |
| } | |
| // Process form. | |
| my_module_special_submit($form, $form_state); | |
| return array( | |
| '#markup' => 'Success. JAVASCRIPT EVENT BEACON.' | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment