1

i have a webform with a lot of fields(i am making some kind of calculator for my needs) and after submit i need to show custom output under my webform.

In hook_form_alter i have added custom submit handler $form['#submit'][] = 'common_webform_client_form_1562_submit_handler';

and after submit i need to show my results on same page.

function common_webform_client_form_1562_submit_handler($form, &$form_state) {
   //some logic here

   //redirect to node with my webform
   $form_state['redirect'] = 'node/1544';
}

As i can see i cannot modify or add anything to a $form i thought i can add #suffix to webform and attach my results but i can't, should i do it with Drupal.settings and grab it with javascript? or is there another option?

1 Answer 1

0

So after some research i have found the answer. I did this with ajax submit. In hook_form_alter i have added ajax submit callback with markup element:

$form['actions']['submit']['#ajax'] = array('callback' => 'common_webform_client_form_1562_submit_handler',
           'wrapper' => 'form-ajax-node-content',
      'method' => 'replace',
      'effect' => 'fade',);
       $form['markup'] = array(
            '#prefix' => '<div id = "form-ajax-node-content">',
            '#suffix' => '</div>',
            '#markup' => '',
            '#weight' => 2000, //set weight to show markup at the bottom of the form
       );

And in my callback i can generate any output i want to!)

function common_webform_client_form_1562_submit_handler($form, &$form_state) {
   $output = 'Dummy text';
   $form['markup'] = array(
            '#prefix' => '<div id = "form-ajax-node-content">',
            '#suffix' => '</div>',
            '#markup' => $output,
            '#weight' => 2000,
       );
    return $form['markup'];
}

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.