I am having difficulty implementing custom validation on a webform submission in Drupal 7 with the Webform module.
The code posted below is contained in a custom module which is activated when the submit button on the form is pressed. I am new to Drupal and php but my understanding is that this code should hook into the webform submission, validate the entries and allow me to manage the data submitted by the user. In the current configuration I would expect to see each of the test codes and the name entered on the form echo back. However, the only code, which returns, is test 4 at the bottom, no error is encountered and it appears not to evaluate any of the other code.
Does anyone have an idea where I am going wrong?
* Implementation of hook_form_alter().
function mywebform_extra_form_alter(&$form, &$form_state, $form_id)
// Add validation for a particular Webform node:
if ($form_id == 'webform_client_form_8')
echo 'test 1';
// Simply add the additional validate handler.
$form['#validate'] = 'mywebform_extra_validate_8';
// 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_8');
* Validation handler for Webform ID #8.
//just make sure that a name was entered
function mywebform_extra_validate_8(&$form, &$form_state)
echo 'test 2';
if ($form_state['values']['name'] == '')
form_set_error('', t('name must be entered.'));
* Submit handler for Webform ID #8.
function mywebform_extra_submit_8(&$form, &$form_state)
// Changes can be made to the Webform node settings by modifying this variable:
// Insert things into other database tables or modify properties.
$name = $form_values['submitted_tree']['name'];
echo 'test 4';