How hook_form_alter works in drupal7 ?

Working strategy of hook_form_alter

This hook perform the alterations before the form is submitted or rendered. This hook hook_form_alter($form, $form_state, $form_id), this hook has 3 parameters

1) $form: Nested array of form elements that comprise the form.
2) $form_state: A keyed array containing the current state of the form. The arguments that drupal_get_form() was originally called with are available in the array $form_state[‘build_info’][‘args’].
3) $form_id: This id should be match to the id of that form, that have to randred by this module.

Now you can create module using this hook to learn it more:
If you are familiar to module development in drupal7, then you can get it easily. First of all you have to create the info file for your module like

name = My Form Alter
description = This is the module using form alter to make changes for the exsiting form
package = custom
core = 7.x

and then you have to create the module file for that

If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.

Recommended Posts:

Article Tags: