I'm creating a webform with multiple pages. On the first page, I ask for "Name" (textfield), and on the second page, I would like to have a markup component that incorporates the value entered for "Name" on the first page.

I have tried using webform's token system in Webform 3.x and the new token functionality in Webform 4.x, as well as hook_form_alter(), all to no avail.

In regard to the later, in glue.module I defined:

function glue_form_alter(&$form, &$form_state, $form_id) {
  if (preg_match("/webform/i", $form_id)) {
   dsm($form);
  }
}

and the resulting array displays the "name" component value (from page one) as empty on page two.

Would someone please help me?

Comments

carsonw’s picture

Status: Active » Closed (fixed)

I found the solution after some elbow grease. The previously entered values are stored in the $form_state variable. So, I check to see if the value exists in the $form_state array and if it does, then I perform a str_replace() on the markup component in the $form array, like so:

function glue_form_alter(&$form, &$form_state, $form_id) {
  if (preg_match("/webform/i", $form_id)) {
    if (isset($form_state['input']['submitted']['name']) && isset($form['submitted']['markup']['#markup'])) {
      $text = $form['submitted']['markup']['#markup'];
      $value = $form_state['input']['submitted']['name'];
      $new = str_replace('TOKEN1', $value, $text);
      $form['submitted']['markup']['#markup'] = $new;
      dsm($form);
    }
  }
}

In the original markup component value, I had entered: Hello TOKEN1. where TOKEN1 is my own custom token text.

cybermache’s picture

Issue summary: View changes

I'm trying to achieve the exact same thing. I have a form that is using a select list on the first page and I'd like to insert the selected value into a paragraph markup on the second page.

I'm a bit confused by your solution, are you applying this function in a custom module named 'glue'?
Or has it been implemented into a webform branch that can be downloaded?

Any extra info on how you got this to work would be awesome.
Thanks

carsonw’s picture

@cybermache - Yes, sorry for the confusion. I am using hook_form_alter in a custom module named 'glue'.