Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

drupal form alter in webform forms

I know that there is possible to use some functions to alter drupal core forms: hook_form_alter(). Can we use this with Drupal forms that are created with the Webform module?

like image 809
Mamadou Avatar asked Feb 24 '11 14:02

Mamadou


3 Answers

In Drupal 7, you can either use hook_form_alter() or hook_form_<formid>_alter(), which ever you prefer. Just make sure you get the naming and parameters right. Drupal 6 only supports hook_form_alter() however.

When you create these functions, also remember that Drupal may not always pick up on them until you've flushed the cache.

Another important thing to note is that if you want to make changes to the webform fields, you have to make changes in $form['submitted']. I made the mistake of originally trying to edit $form['#node']->webform['components'], which has no effect.

More information can be found here: http://drupal.org/node/1558246

Hope that can help.

like image 98
alexkb Avatar answered Oct 18 '22 05:10

alexkb


You can do it,

you just need the id of the node and then use the id like in hook_form_<FORMID>_alter()

the FORMID generated is webform_client_form_<NODEID>

where NODEID is the id of the node

so if you have a module named mymodule and a node with id 44 which has a webform

function mymodule_form_webform_client_form_44_alter(&$form, &$form_state) {
// code here;
}
like image 20
yunzen Avatar answered Oct 18 '22 07:10

yunzen


You can use hook_form_alter(), accessing elements via $form['submitted'].

like image 3
Rulo Kobashikawa Avatar answered Oct 18 '22 05:10

Rulo Kobashikawa