7

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?

0

5 Answers 5

14

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.

Sign up to request clarification or add additional context in comments.

Comments

6

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;
}

Comments

3

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

Comments

0

I am not quite sure what you are trying to do, but since webform module creates a content type - webform - you can alter forms created by webform purely through the admin interface - add new inputs and input types, specify whether they are required or not etc.

for example, a "contact us" form can have whatever inputs you want - unlike the core Drupal contact form which IIRC only has an email address and a textarea.

2 Comments

I would like to capture data in php and do watever i want with
Not quite sure about that. I think webforms can be added to any node type.
0

Yes, if for some reason you need to make a change to the webform which you can't do by editing the webform node, then you can use hook_form_alter to change the form as well, as the webform is created by the form api.

That said, do poke around in some of the corners of webform - it comes with a number of options for dynamically filling or changing parts of the form already.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.