form_set_error not working in node form validation I'm frustrated right now. This very reduced module code shows the problem: 

&lt;?php

function mymodule_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  if ('pic_node_form' == $form_id &amp;&amp; !path_is_admin(current_path()) ) {
    $form['#validate'][] = '_mymodule_pic_add_form_validate';
  }
}

function _mymodule_pic_add_form_validate($form, &amp;$form_state) {
  form_set_error(null, t('Keep calm bro'));
  // die("foo");
}

function mymodule_node_validate($node, $form, &amp;$form_state) {
  form_set_error(null, 'test');
  // die("bar");
}


pic_node_form is the node add form for the content type pic. That form is exposed (hence &amp;&amp; !path_is_admin(current_path())). There is an image upload field involved.

The form_set_error doesnt do anything and nodes keep getting submitted. The die() functions actually work when I remove the //, so the functions do get invoked.

The form itself is placed via block:

function _mymodule_get_block_content($delta) {
  if ('pic_add_form' == $delta) {
    global $user;
    module_load_include('inc', 'node', 'node.pages');
    $node = (object) array(
      'uid' =&gt; $user-&gt;uid,
      'name' =&gt; (isset($user-&gt;name) ? $user-&gt;name : ''),
      'type' =&gt; 'pic',
      'language' =&gt; LANGUAGE_NONE,
    );
    $form = drupal_get_form('pic_node_form', $node);
    $form_rendered = drupal_render($form);
    $markup .= $form_rendered;

    return $markup;
  }
}


Any ideas what I am doing wrong?
If you check the source of form_set_error(), you will see that if you don't supply the name of the form element for which you are setting the error, error messages will not be set.

As long as the first argument is NULL, form will be submitted. Your code was being executed, but it didn't stop the submission.

What you need to do is to pass the name of the field for which you want the error to show. This goes as the first argument for form_set_error().

Example:

form_set_error('YOUR_FIELD_NAME', t('Your message'));