Great module! Can't quite figure out if what I want to do is possible:

  1. Validate form data and store in database
  2. Next, redirect user to an external URL. The URL needs to be constructed based on data entered in the form.

Is this possible with webform module? If not, might it be possible using the form api directly? A previous support request indicated that the type of thing I'm looking for was impossible, but I believe that discussion occurred before the advent of form api version 2.

Thanks for your help!

Comments

isaac77’s picture

Priority: Normal » Minor

So it looks like I just need to include something like the following in "Additional Processing" ("Advanced" section):


header("Location:http://www.google.com/{$form_values['submitted']['number-referencing-form-field']}");
exit();

Could someone confirm if this is the best way to accomplish the task? Does this create any kind of security risk?
THANKS!

Also: is there any way to refer to specific elements in $form_values with a name rather than numbers? Right now I'm using something like $form_values['submitted']['1125812490']

Marc Bijl’s picture

Priority: Minor » Normal

Actually I'm looking for something equal: anonymous users should be able to fill in a quite extensive donation page (the webform), to be directed to a Paypal donation page directly afterwards. If possible, some of the webform fields filled in by the user should be used as "default values" at the Paypal page.

Found how it can be done with CCK (http://drupal.org/node/131807), but in fact I prefer webform :)

So basically I'm kind of subscribing here...

quicksketch’s picture

I found a solution to this today and thought I would share. You can simply set the confirmation option in the $node variable dynamically depending on your needs. In the "Additional PHP Processing' you can enter the following code:

// Internal redirect
$node->confirmation = 'internal:node/20';
// Or external redirect
$node->confirmation = 'http://www.google.com';
// Or even just change the message to the user:
$node->confirmation = 'Thanks for filling out the form!';

All processing will still be done as normal. If needed, you can also access the entire submission in the $form_values variable. In webform 1.3 and later, keys can be given to webform fields to make this process easier than trying to hunt down the right random numeric keys in the $form_values variable.

apratt’s picture

Quick note...

To use the key rather than the numerical reference you must use 'submitted_tree' rather than 'submitted'

scafmac’s picture

Actually, I'm not sure that will work as you expect. If you look at the code, the submission is not recorded in the database until after the additional processing is performed. That means if you redirect the page in the additional processing field, it will be redirected before it is recorded in the database.

An alternate solution I've implemented and am testing now is to create a webform submission hook. It will be called just before the natural redirection would occur, which is well after the email submission and databased logging. This is a more flexible, albeit more complicated, solution. It is more complicated only because you would need to create a mini module to house the function hook_webform_submission, but I believe it is needed for any real post processing of of the form submission - issue http://drupal.org/node/159761

Oh also for New Oceans, there is already a module that integrates with Paypal http://drupal.org/project/simple_paypal & modules that use it - not sure if you were aware.

scafmac’s picture

Quicksketch - I hadn't read your fix carefully enough before, as I thought you were redirecting with the additional processing stuff rather than altering the confirmation. My mistake - I'll give this a try and see if it works for my needs.

Offhand it doesn't seem like the best solution because it requires the content maintainers to create/cut & paste php code. Besides the security question, I don't like needing to teach site maintainers what php code to add to the additional processing section - it is tough enough just to teach them to use the webform interface never mind php. And the php could get pretty complicated when you start constructing complicated urls - seems like something that should be left to developers not content creators.

This post might help others - http://drupal.org/node/159761

scafmac’s picture

FWIW, the solution from #3 doesn't work so well if you use Tiny_mce on node/* pages or if you are constructing urls that have get variables including email addresses - the @ symbol seems to break it. Not sure what other chars would also break it.

Neither is insurmountable - but it's a hassle.

quicksketch’s picture

Status: Active » Closed (fixed)