function webform_paypal_submit in Webform Paypal 7.2
Same name and namespace in other branches
- 7 webform_paypal.module \webform_paypal_submit()
Submit function to send user to paypal after form values saved.
1 string reference to 'webform_paypal_submit'
- webform_paypal_form_alter in ./
webform_paypal.module - Implements of hook_form_alter().
File
- ./
webform_paypal.module, line 264
Code
function webform_paypal_submit(&$form, &$form_state) {
$submission_id = $form_state['values']['details']['sid'];
$nid = $form_state['values']['details']['nid'];
//I guess its better than a node load
if (drupal_lookup_path('alias', 'node/' . $nid)) {
$node_path = drupal_lookup_path('alias', 'node/' . $nid);
}
else {
$node_path = base_path() . 'node/' . $nid;
}
global $base_url;
$submission_url = $base_url . $node_path . '/submission/' . $submission_id;
//lookup our hidden webform values from the form
//we don't know the name because that is editable by end user
$webform_components = $form_state['webform']['component_tree']['children'];
foreach ($webform_components as $key => $value) {
if ($value['type'] == 'paypal') {
$paypal_component_name = $value['form_key'];
if ($value['extra']['transaction'] == 'live') {
$url = 'https://www.paypal.com/cgi-bin/webscr';
}
else {
$url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
}
}
}
$post_data = array();
$post_data['cmd'] = '_s-xclick';
$post_data['hosted_button_id'] = $form['submitted'][$paypal_component_name]['#default_value'];
//send return path to submission for better tracking
$post_data['custom'] = $submission_url;
drupal_goto($url, array(
'query' => $post_data,
));
}