Redirect webform submissions to a dynamic URL in Drupal 6

If you need a way to redirect webform submissions to a dynamic URL in Drupal 6, using the Webform PHP module can work well with Webform 3.x.  I recommend only using post processing conditionals on select fields if possible with Webform PHP since you need to enable the permission to "use PHP for additional processing" for users who submit webforms (typically anonymous).

Here's the process:

  • Install Webform and Webform PHP
  • Allow the appropriate users to have the "use PHP for additional processing" permission under Admin > User Management > Permissions
  • Create two new pages with the following URL aliases: 'submitted' and 'formredirect'
  • Create a webform with all your components
  • Go to the webform tab, then form settings for the form you created
  • Redirect the form to "custom page" and enter in a new page you create with Drupal, ie http://example.org/formredirect
  • Go to the bottom of form settings, and under additional processing do the following:

<?php
  if ($form_values['submitted_tree']['fieldset']['fieldname_under_fieldset'] == '0' && $form_values['submitted_tree']['fieldset_last_page']['fieldname_under_fieldset'])
 
   {
    $_SESSION['exredirect']['redirect_url'] = 'http://example.org/submitted?s=n';
  }else{
    $_SESSION['exredirect']['redirect_url'] = 'http://example.org/submitted?s=y';
}
?>

  • In this code, the field on the last page is underneath a fieldset named "fieldset_last_page" (not the label, the actual name).  Both fields we check against are selects.  The "0" in the first is a key value assigned in the select when you configure that component.  Both of these selects are under a fieldset.  If you're not under a fieldset, you can remove the second set of brackets.  What this does is set a session variable with the final page we want to redirect to.
  • Now, go to the formredirect page you made earlier, enable PHP on it under Input Formats, and do the following:

<?php
// get information from our session
if (!empty($_SESSION['exredirect']['redirect_url'])) {
    // redirect to path
    drupal_goto($_SESSION['exredirect']['redirect_url']);
}
else {
    // redirect to frontpage
    drupal_goto('submitted');
}
?>

  • This will do the redirect to submitted with the ?s=n or ?s=y parameter, depending on what your session was set to.  If there's no session it will just redirect to the submitted page with no parameter.  Now, on your submitted page do the following:

<?php $s = $_GET["s"]; 
if($s == 'y'){ ?>Something here, s is "y"
<?php } ?><?php
if($s == 'n'){ ?>
Something else here, s is "n"
<?php } ?>

  • This final code grabs the parameter from the URL and shows appropriate content.

There are many variations on this but the method here worked for me without much trouble.