Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The error|warning|status messages by default display on the top of page after validation of form or success submission, but sometimes you need to display this messages on the top of form, So the following code solve this issue:
/*
* hook_form_alter()
*/
function MODULENAME_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'FORMID') {
$form['#validate'][] = 'ie_form_validator';
}
}
function ie_form_validator(&$form, &$form_state) {
$form['ukife_form_validator'] = array(
'#markup' => theme_status_messages(array('display' => 'error')), // you can use 'status', 'warning'
'#weight' => -1000,);
}
Comments
Comment #2
m.attar CreditAttribution: m.attar commentedComment #3
m.attar CreditAttribution: m.attar commentedComment #4
Snater CreditAttribution: Snater commentedI do not see that being required by the Insert module as the Insert module provides a button that triggers JavaScript functionality only by attaching to some existing file/image field. There is no functionality provided by Insert that could trigger some message when saving the form.