Hi folks,

In addition to processing by webform, I need to post the results to an additional script (hosted elsewhere). I'm planning on using drupal_http_request in the "advanced" field to do this. Has anyone done this and is willing to share how?

Thanks in advance.

Comments

samhassell’s picture

I would also be interested in possible solutions to this problem. I was thinking curl but now i see drupal_http_request exists, i guess that is the way to go.

avangelist’s picture

I take it nobody did anything with this?

I would like to send the form to another form action on an external server via url.

mtndan’s picture

Not yet... would still love to see an example from someone much smarter than myself (which won't take much!)

quicksketch’s picture

This will resubmit the Webform data to a second webserver:

$url = 'http://example.com/mycustomscript.php';
drupal_http_request($url, array(), 'POST', $form_values['submitted_tree');
shanefjordan’s picture

The code was missing a bracket at the end of $form_values.

<?php
$url = 'http://example.com/mycustomscript.php';
drupal_http_request($url, array(), 'POST', $form_values['submitted_tree']);
?>

Thank you for the info, I will attempt using this method.

- Shane

avangelist’s picture

Nice touch, do you know if there si a way to explode that content first to assign the tree items alternative ID's?

glad I nudged this one along

quicksketch’s picture

avangelist, I'd suggest editing your Webform components, then while editing each one, expand the "Advanced" fieldset and give the field a new "Form key" which matches whatever your other script is expecting.

avangelist’s picture

I see so form key should equate to name or ID?

I got a php script which is for a 3rd party app which picks up details from the name field in an input element.

avangelist’s picture

And just to be even more of a pain in the ass - webforms doesn't allow case sensitivity. Seriously how sodding difficult does it need to be to make a poxy web form - essentially the most basic and bog standard html processing script ever created.

This is bloody stupid.

All I want to do is take my existing html webform and bang it on a page on a drupal site why make it so frikkin impossible to do?

budda’s picture

@avangelist ranting like that isn't going to make you any friends.

samhassell’s picture

@avangelist: if you don't want to take the time to learn Webform or the Forms API, just create a node, set it to the Full HTML input format and paste your form in.

It will work but you'll be missing all the Drupally goodness. And violating best practices. But the option is there.

shanefjordan’s picture

I have attempted using the drupal_http_request and it does not look as though it is going to my other script. So, I took the code behind drupal_http_request and created a php script with it, passed it the same values, and it works fine. My next step was to take that code from the custom script and paste it into the additional processing. It does not work again. It does not give me any error message, just goes to my confirmation page. How can I get it to stop and give me some kind of error message or the $result.

- Shane

quicksketch’s picture

Generally for debugging, I find the devel.module indispensable. You can't use print() or echo() statements in the Additional validation or submission code, since it's all executed in an eval() function in the submission handling. Instead, after installing devel module, you can use the dsm() function to print out the status of variables to the message area of Drupal. It works just like print_r() only it'll save the value to the SESSION instead of printing out immediately.

shanefjordan’s picture

Thank you for the response, I have figured out the issue. I actually had to do a little more than what was listed earlier in this topic. Here is the code I used:


<?php
$url = 'http://www.somehwere.com';
$headers = array('Content-Type' => 'application/x-www-form-urlencoded');
$data = array (
    'first_name' => $form_values['submitted_tree']['first_name'],
    'middle_name' => $form_values['submitted_tree']['middle_name'],
    'last_name' => $form_values['submitted_tree']['last_name']);
$result = drupal_http_request($url, $headers, 'POST', http_build_query($data, '', '&'));
?>

Because the script I am passing this to is parameter based, it was easiest to populate my own variables, rather than passing everything (all the hidden values). But that still wasn't enough, I had to add the data array into the http_build_query and pass the additional parameters for separation.

- Shane

djalloway’s picture

To turn a Webform into a Salesforce Web-to-Lead form.

Although it is not directly recommended to use Webform in this way, hopefully it will still be helpful to some people out there.

Please note that the Form Components in your Webform must have their Field Keys match the Salesforce Fields that you want to use.
You must also include the OID field that you get when you generate a Salesforce Web-to-Lead form as a hidden field within your Webform.

// This is the URL given to me via the "Web-to-Lead Setup" page on my Salesforce account.
$url = 'https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8';

// Be sure to set the correct headers as required by Salesforce.
$headers = array('Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8');

// Assemble our data into the typical 'form submission' format as expected by Salesforce.
$data = http_build_query($form_values['submitted_tree'], '', '&');

// Compile everything and dispatch the request.
$req = drupal_http_request($url, $headers, 'POST', $data);

**NOTE**
Because the Salesforce URL for Web-to-Lead submissions is secured (HTTPS) I had to make sure that the OpenSSL extension was enabled and working within my PHP configuration.

quicksketch’s picture

Status: Active » Closed (fixed)
kaldazar’s picture

Last webform does not allow php snippets. Where can I add the above code to get the same result?

I desperately need it.

djalloway’s picture

Well, another option would be this.
Make it a new module and throw it in one of those new Webform submission hooks.
Probably this one hook_webform_submission_insert($node, $submission)
Test to make sure it's the Node that you want and then process your PHP code.

djalloway’s picture

Or you can just install, http://drupal.org/project/webform_php
As, that is where the Additional Processing functionality has moved to.

bluesband’s picture

Hi,
Thanks for sample codes. #15 it's works! But, how to get file field content in destination php file?

tvu007’s picture

Status: Closed (fixed) » Needs review

Thanks for the sample code as well @djalloway. This is extremely helpful, since I am seeking to use this additional processing to init the web to lead. The other community salesforce module as well salesforce web form integration require the saleforce API (developer, enterprise, or unlimited) versions of sale force.com. Bsically the API access and API enabled permissions are only available in those versions. I have salesforce professional standard edition for my organization. Hence, your method works well and also triggers assignment rules. Using the other modules make use of the salesforce API thru web services and apex. This does not trigger the Inherent and usable assignment rules in salesforce.com.

My issue as it stands to your additional processing method using web to lead. Why is it that values associated to checkboxes or select list fields are not passed to salesforce.com when using method #15 above. Text field input seems to work and pushed over but not select fields and checkboxes. Is there some additional handling of the form values that is missed in #15?

bluesband or djalloway got many ideas? I am stuck at the moment...

quicksketch’s picture

Status: Needs review » Closed (fixed)

I'm closing this issue as I'm generally discouraging users to paste PHP code into text areas. In any case, support for custom coding is not (or more accurately, no longer) provided in the Webform issue queue.