I have a working webform which checks the user input and after the (anonymous) user submits the webform, I would like to serve them one of three webforms where they can fill in additional information. I tried to achieve this with the conditional confirmation message module, but it keeps giving me the default thank you message instead of the custom URL. Although I filled in the custom URL correctly, pointing to the right form(s).

So I tried the manual way: Because I already had a working module with hooks for the custom validation rules, I tried the alter_form approach. My form-id is correct because I get a drupal_set_message with this code:

function custommodulename_form_alter($form, $form_state, $form_id) {
 $nid = 2291;
  if ($form_id == 'webform_client_form_' . $nid) {
    $form['#submit'][] = '_my_custom_action';
    drupal_set_message("Test1: ".print_r($form['#submit']));
  }
 }

The confirmation message displays the following: Array ( [0] => webform_client_form_pages [1] => webform_client_form_submit [2] => _my_custom_action )

But my custom action hook doesn't get executed:

function _my_custom_action($form, $form_state) {
	drupal_set_message("Test2");
    $option['query'] = array(
    'code' => $form_state['values']['eindejaarsactie_code'],
    'email' => $form_state['values']['eindejaarsactie_emailadres'], 
   );
   $url = url('http://google.be/', $option);// (valid path or whatever)
   $form_state['redirect'] = $url;
}

Instead the default submission thank you message is displayed, instead of redirecting the (anonymous) user to the custom URL.

Can someone please help me achieve this? I don't even know how to debug this... How can you check the cause of a custom hook not getting executed? Or do you see something obviously wrong with my approach?

Comments

helonaut’s picture

Issue summary: View changes
helonaut’s picture

Issue summary: View changes
DanChadwick’s picture

Status: Active » Fixed

We don't supply custom code support in the webform issue queue due to resource constraints. You might have luck with the forums or IRC.

You could simply implement kreatos_eindejaarsactie_form_webfdorm_client_form_XXXX_alter($form, $form_state, $form_id).

Step through the form handling (calling the submit handlers) with something like XDEBUG to see what's happening.

Good luck!

helonaut’s picture

Issue summary: View changes

OK thank you for the information Dan.

helonaut’s picture

For anyone else fighting with this approach...
$form_state['redirect'] = $url;
did nothing for me, while:
$form_state['build_info']['args'][0]->webform['redirect_url'] = $url;
did.

Hope I made somebody happy with posting this... Lost a couple of hours fighting over achieving custom redirection in 4.x ...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.