I'd like to have a simple feedback form that is submitted via AJAX, using Drupal 7. Upon receipt of the form, I want a simple jQuery modal dialog to appear that will say something along the lines of "Thank you for your submission, etc.". The browser standard alert does accomplish this, but my client feels that this looks unprofessional, hence the desire for the more nicely styled jQuery dialog.
Using ajax_command_alert()
causes the browser to use a simple alert()
function. Is there any way to force usage of the jQuery modal dialog? For reference, my code is below:
function feedback_form($form, &$form_state) {
$form['first_name'] = array(
'#type' => 'textfield',
'#title' => 'First Name',
);
$form['last_name'] = array(
'#type' => 'textfield',
'#title' => 'Last Name'
);
$form['email'] = array(
'#type' => 'textfield',
'#title' => 'Email'
);
$form['comments'] = array(
'#type' => 'textarea',
'#title' => 'Comments'
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit Feedback',
'#ajax' => array(
'callback' => 'feedback_form_submit'
)
);
return $form;
}
function feedback_form_submit($form, &$form_state) {
$commands = array();
$commands[] = ajax_command_alert("Form received");
return array('#type' => 'ajax', '#commands' => $commands);
}
EDIT: I see that the alert function is defined in misc/ajax.js, under Drupal.ajax.prototype.commands. If I were to alter the JS file's implementation of alert, this would work - but that would be considered hacking core, I believe. How else could I alter this function?