I have two forms on a node page (the comment one + a custom form). Ajax is not enabled for both of them but still, when submitting the custom form form_set_error or durpal_set_message are not displayed but displayed when you load a new page (if you submit the form again, if you reload a page or if you change the page). It's like I have a hidden ajax behavior messing the submit up.

function my_module_quote_request_form($form, &$form_state) {
  global $user;
  $account = user_load($user->uid);

  $user_phone_number = $account->field_user_address[LANGUAGE_NONE][0]['phone_number'] ? $account->field_user_address[LANGUAGE_NONE][0]['phone_number'] : '';

  $form = array();

  $form['phone_number'] = array(
    '#type' => 'textfield',
    '#title' => t('Phone number'),
    '#default_value' => $user_phone_number,
    '#size' => 30,
    '#maxlength' => 10,
    '#required' => TRUE,

  $form['actions'] = array('#type' => 'actions');
  $form['actions']['submit'] = array(
    '#title' => t('Submit'),
    '#type' => 'submit',
    '#value' => t('Request'),

  $form['actions']['cancel'] = array(
    '#title' => t('Cancel'),
    '#markup' => l(t('Cancel'), '/market'),

  return $form;

function my_module_quote_request_form_validate($form, &$form_state) {
  if (blabla) {
   form_set_error($phone_number, $message);

If you trigger blabla, then the message is not displayed but displayed on page reload.

Any idea what it can due to?

  • Can you check to see if the rendered form ids are the same per chance? Sep 17, 2018 at 15:23
  • They are not for sure. The second form is the comment one (I print it in the page and have some JavaScript tabs to make it easier to comment).
    – Aporie
    Sep 17, 2018 at 18:21

1 Answer 1


I have finally found what was the issue. It's absolutely not related to the fact I have two forms but that I was implementing my theme variable in a node preprocess function.

Errors messages are prepared in upper function so the result is that you alter a variable after it's actually called. The result is the message is displayed on reload.

See here : form_set_error message delayed one page refresh

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.