1

I have a webform on my site and on user submission, I want to send the webform data to some php application that get the value of some variables from the URL.

This task requires me to access the webform submitted data when the user clicks "Submit" button and construct a URL (/myphpapplication?query=....) containing user filled webform values. Please help me to achieve this.

2

As Oswald mentioned, you have to implement some hooks in your custom module to redirect your form submission. Here is a quick example (assume your form_id is 'webform_client_form_1'):

// hook_form_alter()
function customform_form_alter(&$form, &$form_state, $form_id) {

if ($form_id == 'webform_client_form_1') {
    // Add form_submit() handler
    $form['#submit'][] = 'customform_webform_submit';
}

}

// form_submit()
function customform_webform_submit($form, &$form_state) {

// Submited values are in $form_state['values']['submitted_tree']
$field_values = customform_webform_values( $form_state['values']['submitted_tree']    );

// Build URL Query
$query = '';

foreach ($field_values as $value) {
    $query .= $value . '&';
}

$redirect = array ( 
                'myphpapplication',
                array (
                    'query' => array ( 
                        'query' => rtrim( $query, "&" )  // Get 'query' values with $_GET['query']
                    ) 
                ) 
            );

$form_state['redirect'] = $redirect;

}

// Recurse through webfrom submited values
function customform_webform_values($component) {

static $webform;

foreach($component as $key => $value) {
    if (is_array($value)) {
        customform_webform_values($value);
    }
    else {
        $webform[$key] = $value;
    }
}

return $webform;
}

  • Thanks A Lot Gabriel.....now I got it how to make it work...one thing that it should be $form_state['values']['submitted'] not $form_state['values']['submitted_tree'] – Deepak Aug 18 '12 at 14:46
0

Implement hook_form_alter() or one of its relatives by adding a submit handler to the form (i.e. to $form['#submit']).

To find out the proper value of the $form_id parameter, your first implementation of hook_form_alter() can just drupal_set_message() that parameter. Use the same technique to find out how your submit handler receives the form values in $form_state['values'].

0

I'm late to answer but maybe it can help someone

Webform 4 data can also be accessed using Webform hooks, as in the following code.

function mymodule_webform_submission_insert($node, $submission) {
  if ($node->nid == 1) {
    $submitted_data = $submission->data;
    print_r( $submitted_data); // This will give you all the submitted value in a form of array which you can use according to your requirements.
  }        
}

You can implement it in a custom module: Don't forget to replace mymodule with your module name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.