Alter Webform using hook_form_alter()

Public
</> CopyGet raw version
php
  1. function mymodule_custom_form_alter(&$form, &$form_state, $form_id) {
  2. if ($form_id == 'webform_client_form_1234') {
  3. $form['submitted']['component_name']['#title'] = 'New Title';
  4. }
  5. }

Comments

pjcdawkins's picture

I find it more concise to use hook_form_FORM_ID_alter(), and the form ID is always "webform_client_form".

  1. /**
  2.  * Implements hook_form_FORM_ID_alter().
  3.  */
  4. function mymodule_form_webform_client_form_alter(&$form, &$form_state) {
  5. $node = $form['#node'];
  6. if ($node->nid == 1234) {
  7. $form['submitted']['component_name'][#title'] = 'New Title';
  8. }
  9. }
Anonymous's picture

@pjcdawkins: I totally agree with you...

yuvaraj's picture

How to subtract two time stamps using hook_form_FORM_ID_alter().
$ot = $form_state['input']['submitted']['opening_time'];
$ct = $form_state['input']['submitted']['closing_time'];
$ot = strtotime($ot);
$ct = strtotime($ct);
$tt = $ct->diff($ot);
form_set_value(
$form['submitted']['total_time1'], $tt, $form_state);

the above code is not working, please help me.