1

I have a form and on and implemented a ajax submit callback which calls this function:

function popover_ajax_callback($form, &$form_state) {
    // watchdog("ajax_callback", "testing ajax callback", array(), WATCHDOG_ALERT);
    return '<div id="ajaxchanger">' . $form_state['values']['first']['field_firstname'] . '</div>';
}

How do I check if the form failed or passed validation within this function?

5
function popover_ajax_callback($form, &$form_state) {
  $errors = form_get_errors();
  if( $errors ) {
    // error detected, do something
  } else {
    // everything is ok
  }
}

but your return value is not ok. You need to return an renderable array. You may want to try someting like this:

return array('#markup' => '<div id="ajaxchanger">' . $form_state['values']['first']['field_firstname'] . '</div>');
| improve this answer | |
  • actually my return value works. Is this just not following the standards then? – FLY May 15 '12 at 14:43
  • yeah, something like that :) but if it works, I think it's ok. it isn't such a big deal... – Marius Ilie May 15 '12 at 14:48
  • A year later but I now understand I should have used a renderable array as return value ;) – FLY May 29 '13 at 14:33

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.