When a webform is validated it does not send the Drupal message "X field is required", it creates only the red border around the field.

How would I show the Drupal messages from triggering during validation? It is a block view of webform in drupal 7.

  • Are you using web from validation module? – DEVARAJ JOHNSON Feb 20 '15 at 13:07
  • no, using only webfrom module – Aslam A Feb 20 '15 at 13:22
  • add a form alter and add #validate and validate the filed you want – DEVARAJ JOHNSON Feb 20 '15 at 13:55
  • are you trying the solution got any idea? – DEVARAJ JOHNSON Feb 20 '15 at 16:22

Webform Validation module can be used to add validation in field of webform.


Another powerful option is using 'Rules'. Install the 'Rules' module and the 'Webform Rules' and the 'Token' module.

Now we will create a custom Rule.

Go to /admin/config/workflow/rules

  1. Click '+Add new rule'
  2. Enter something in the 'Name' Field.
  3. For the 'React on event' Field choose 'After a Webform has been submitted'.
  4. On the next page you will see 'Conditions' and 'Actions'
  5. Under conditions add the condition that generates the validation behavior
  6. Under Actions click the 'Add an action' link. Choose 'Show a message on the site'
  7. Under the 'Message' field write your message. You will see a 'Replacement Patterns' link/expand thing. Expand it and you will be provided with a ton of tokens that you can use to make a detailed error message based on available Fields.
  • This is a bit heavy handed. Plus, if the webform has been submitted, you already received the data that wasn't validated. OP wants to prevent submission until fields are validated, and have the error messages display on the screen. – Kevin Jul 5 '16 at 18:27

you can implement hook_form_alter as implement below :

function YOUR_MODULE_NAME_form_alter(&$form, &$form_state, $form_id) {

    if ($form_id == "your_webform_id") {
       $form['#validate'][] = 'yourwebform_custom_validate';

// Implement Callback
function yourwebform_custom_validate($form, $form_state)
    if ($form_state['values']['your_field_name']['und']['0']['value'] < 0) {

        form_set_error('your_webform_id', t('Your Error Message'));


According to the original question:

"it creates only the red border around the field."

This would make it seem to me that $messages is not being printed out in the theme. That would be the first thing to look for in my opinion. The form is being validated but the messages from form_set_error are not being output.

If you are not using ajax, it is likely a good place to start.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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