Can't see error messages when creating Drupal form in a separate file Suppose, I want to use Drupal libraries inside a separate php file to generate a form. I created 3 functions:


function add_form
function add_form_validate
function add_form_submit


And then used drupal_get_form / render to get the HTML code. But when I insert invalid data, I don't see the error message - just the red border of the text input. Here is the minimal example to reproduce the error (file is called test.php and is located inside Drupal directory):

&lt;?php
//including Drupal libraries
define('DRUPAL_ROOT', $_SERVER['DOCUMENT_ROOT']);
require_once(DRUPAL_ROOT . DIRECTORY_SEPARATOR . 'includes'.  DIRECTORY_SEPARATOR . 'bootstrap.inc');
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

//form with 1 text field and submit button
function add_form($form, &amp;$form_state)
{
    $form['text'] = array(
        '#type' =&gt; 'textfield',
        '#title' =&gt; 'Insert text',
        '#required' =&gt; true,
        '#attributes' =&gt; array('autofocus' =&gt; 'autofocus'),
        );

    $form['submit'] = array(
        '#type' =&gt; 'submit',
        '#value' =&gt; 'Submit',
        );

    return $form;
}

//text must be 'aaa'
function add_form_validate($form, &amp;$form_state)
{
    if ($form_state['input']['text'] != 'aaa')
    {
        form_set_error('text', t('Text is not aaa!'));
    }
}

function add_form_submit($form, &amp;$form_state)
{
    print "I am inside add_form_submit&lt;br&gt;";
    var_dump($form_state['input']);
    exit;
}
?&gt;
&lt;!DOCTYPE html&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;element&lt;/title&gt;
    &lt;link type="text/css" rel="stylesheet" media="all" href="/modules/system/system.base.css"&gt;
    &lt;link type="text/css" rel="stylesheet" media="all" href="/modules/system/system.theme.css"&gt;
    &lt;link type="text/css" rel="stylesheet" media="all" href="/modules/system/system.messages.css"&gt;
    &lt;meta http-equiv="Content-Type" content="text/html;charset=utf-8" &gt;
  &lt;/head&gt;
  &lt;body&gt;
&lt;?php
//here is the problem: I don't know, how to output the error message
print theme('status_messages');

$content = drupal_get_form('add_form');
$content = render($content);
print $content;
?&gt;
  &lt;/body&gt;
&lt;/html&gt;
It is working fine for me, only thing is that I get the error message only when submitting for the second time, that is because you are printing the status message before the drupal_get_form(). So if I print the message after drupal_get_form() then it is working as expected.