EDIT: Still need some help with this. It seems the value of "$form_id" is nothing related to "webform_client...". When I echo the value of $form_id in the mywebform_extra_form_alter() function it outputs a value of: "search_form_block".. nothing indicating a webform.

Can I ask for some more assistance with this?

I've created a module for a webform submission hook to open and modify a CSV with the submitted values:

function mywebform_extra_form_alter(&$form, &$form_state, $form_id) {
    // Add validation for a particular Webform node:
    if ($form_id == 'webform_client_form_213') {
    // Add the submit handler after the existing Webform submit handler,
    // but before the second Webform handler. Pop off the first one and add
// ours second.
    $first = array_shift($form['#submit']);
    array_unshift($form['#submit'], $first, 'mywebform_extra_submit_213');

function mywebform_extra_submit_213(&$form, &$form_state) {

    global $user;

    // Changes can be made to the Webform node settings by modifying this variable:

    $name = $form_state['values']['your_name'];
    $email = $form_state['values']['your_e_mail_address'];
    $zip_code = $form_state['values']['zip_code'];
    $date = date('m/d/Y');

    $handle = fopen("pledge_submissions.csv", "a");
    $line = array($name,$email,$zip_code,$date);
    fputcsv($handle, $line);


It seems these functions are firing but when I open the CSV, no data has been added.

Is $form_state['values']['field_name_here'] the correct way to target the webform field values? When I try to alert things inside that function the form errors out after submission.

  • My guess would be that fopen file path is not correct. Use a debugger like xdebug to step through the submission function and review scope.
    – Kevin
    Sep 27, 2016 at 20:10
  • How about the targets though? $form_state['values']['your_name'] Sep 27, 2016 at 20:24
  • Step through the code to inspect variable scope. I don't know what the form state structure would be off hand, but I suspect it could be slightly different than a standard form submit (since this is Webform).
    – Kevin
    Sep 27, 2016 at 20:25

1 Answer 1


Two things:

Check your argument to fopen for validity, and two, the $form_state in Webform is missing a key. Example:

  $data = array(
    'full_name' => $form_state['values']['submitted']['full_name'],
    'company' => $form_state['values']['submitted']['company'],
    'phone' => $form_state['values']['submitted']['phone'],
    'email_address' => $form_state['values']['submitted']['email_address'],
    'areas_of_interest' => array(),
    'comments' => $form_state['values']['submitted']['comments'],

You are missing ['submitted'].

  • I appreciate the answer. I tried your solution but unfortunately the hook doesn't seem to fire. What I notice is the $form_id value is not passing in like I thought it would. Instead of "webform_block_client_213" its "search_form_block" Oct 11, 2016 at 21:36
  • In your original question you said the functions are firing.
    – Kevin
    Oct 11, 2016 at 23:39
  • I did. You are correct. I may have been wrong. Oct 11, 2016 at 23:43
  • hook_form_alter will be hit multiple times as the page is being built if you have more than one form on the page. Continue debugging until you get the right form id and go from there - let the request finish, dont terminate it.
    – Kevin
    Oct 12, 2016 at 0:02

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.