how to do an drupal form submit using ajax?
i have a custom module, in which i am subm开发者_开发问答itting the form using drupal submit. ie using mymodule_submit() function. i want to ajaxify this submit using jquery. what all are the prerequisites for ajaxifying in drupal ? how to return the values and all? somebody please help . thanks in advance
Several high-level concepts are important:
- do it trough forms api. technically you can circumvent it and write your own form-tags (in plain HTML) but that brings more problems then its worth.
- changing the behaviour of any form, is done in a so called hook_form_alter()
- Changing the look and feel of any form is done in the theme layer
- Then you can add ajaxified behaviour to a theme using AHAH. Note that in Drupal AHAH is slightly misnamed: it is only a particular subset and works only for forms.
There are 2 ways:
If you dont need to capture the submit response: Create a hidden iframe, and change the "target" attribute of the form to the iframe name. This can be done in 2 javascript lines, after form rendering.
If you need to capture response: Use Jquery form plugin, so after submit you need to give a callback function passing he response as argument.
http://drupal.org/project/examples
- you can refer to example module. It contains different types of ajax forms
精彩评论