I use this PHP snippet on the server side after a submission of a webform:
function mymodule_webform_submission_insert($node, $submission) {
// $node will give you the node id of your webform
// $submission will give you the id of your data which you inserted in web form
$sid = $submission->sid ? $submission->sid : FALSE;
if($sid){
dsm($sid); // yes, the sid is shown after a submission
if(!isset($_SESSION['mymodule'])){
$_SESSION['mymodule'] = array();
}
$_SESSION['mymodule']['webform_id'] = $sid;
drupal_add_js(array('mymodule' => array('webform_id' => $_SESSION['mymodule']['webform_id'])), 'setting');
}
}
... and then on the client side I have ths JS snippet:
(function ($) {
Drupal.behaviors.mymodule = {
attach: function (context, settings) {
var sid = Drupal.settings.mymodule.webform_id;
console.log('the submission ID is: '+ sid);
}
};
}(jQuery, Drupal));
.. but the variable sid is "undefined" in the console (after a submission) no matter what I try to do. Can anyone see what I am doing wrong?
if($sid){
block is being entered in your PHP code?Drupal.settings.mymodule
in the console.