I have multipage webform. I want to compute the value of the component (Hidden -type) which is on the second page based on the data submitted on the first page.

I'm using hook_form_alter and added my client_submit handler:

function mymodule_client_submit(&$form, &$form_state)

I can read there submitted data from the first page and I can do the calculation. But I cannot set the value of the component from the second page. I can see the structure of the form in $form or $form_state parameter. But I do not know how to set the value of the component from the second page as it was not submitted yet.

1 Answer 1


I can suggest you a simple way to do this. You can pass the calculated value stored in a variable to the next form function.

Like I had two step form & at first step of the form user select some name from given name(checkboxes), I store them in array & pass them to the next form function like --

function MYMODULE_form($names)//Use your module name instead of MYMODULE.
  $return_form = drupal_get_form('MYMODULE_get_form', $names);
  return drupal_render($return_form);
function MYMODULE_get_form($form, &$form_state, $names)
  $form = array();
  $i = 0;
  foreach($names as $name)
    $form['item']['name'.$i] = array(
      '#type' => 'markup',
      '#value' => $name,

Try something like this, if it solves your problem. Use simple variable if you don't have multiple values.

  • You can use hook_form with passing your own variable too. Here MYMODULE_form is the function which will be called in next step of your form.
    – RajeevK
    Commented Sep 20, 2013 at 4:36
  • I tried your code, but it's not working: any markup fields are rendered on the second page. Commented Sep 20, 2013 at 4:52
  • I found the function MYMODULE_form($names) is not called. Even I use function signature like function MYMODULE_form($form_id, &$form_state) it is not called. Commented Sep 20, 2013 at 5:18
  • @PetrFelzmann - Paste your full code somewhere & link it here..
    – RajeevK
    Commented Sep 20, 2013 at 12:32
  • I created module called mt_booking and inside mt_booking.module file I have this code: <?php function mt_booking_form($names) { drupal_set_message('foobar'); } ?> No message is displayed. Commented Sep 20, 2013 at 17:46

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.