2

In webform 7.x-4.10 I created a module like this:

function webform_presave_webform_submission_presave($node, &$submission) {
  if ($webform->nid == 28) {
    $component_id = 1;
    $submission->data[$component_id]['value'][0] = 'Yes';
  }
}

My webform with nid 28 has only one field, a texfield with a default value to "No".

When the webform is submitted, the value of the field is not change...

What am I doing wrong?

2
  • there is a typo in the code, it is not "if($webform->nid == 28)" it is "if($submission->nid == 28)" but the problem is the same, it's not working ^^
    – Fumble
    Commented Oct 6, 2015 at 12:08
  • In fact after reading webform.api.php in the webform directory, the ['value'] in "$submission->data[$component_id]['value'][0]" has nothing to do there!
    – Fumble
    Commented Oct 6, 2015 at 12:21

2 Answers 2

1

The reason why the value of the field does not change (assuming the name of your module == webform_presave) is due to the fact that the if statement fails because $webform is not defined. Use this instead:

function webform_presave_webform_submission_presave($node, &$submission) {
  if ($node->nid == 28) {
    $component_id = 1;
    $submission->data[$component_id]['value'][0] = 'Yes';
  }
}

See hook_webform_submission_presave() in webform.api.php.

0

Notice the value on which you check in the if.

the correct code is:

function webform_presave_webform_submission_presave($node, &$submission) {
  if ($submission->nid == 28) {
    $component_id = 1;
    $submission->data[$component_id][0] = 'Yes';
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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