I have a site-wide contact form setup that redirects the user to the homepage and posts the submission result to the help section. It works as intended, but I was wondering what I would need to do to change this behaviour.
Instead of redirecting, I would like to display the form submission result in a modal (maybe jQuery) popup.
How could I achieve this?
I wouldn't like to lose the core functionality, just maybe override it with a custom module or something. Any thoughts?
EDIT:
Starting with @rémy 's suggestion, I created a .module
file where I'm trying to override the standard behavior for form submission.
Right now the only thing I have is as follows (although it doesn´t work):
<?php
/*
* Override the the form submit behaviour.
*/
function modal_contact_form_result_form_node_form_alter(&$form, FormStateInterface $form_state, $form_id){
$form['actions']['submit']['ajax'] = array(
'callback' => 'ajax_test_dialog_form_callback_modal'
);
}
function ajax_test_dialog_form_callback_modal($form, FormStateInterface $form_state){
$response = new AjaxResponse();
$content = 'Form submitted successfully, thank you!';
$title = 'YForm submited';
$response->addCommand(new OpenModalDialogCommand($title, $content, array('width' => '700' )));
return $response;
}
But at this moment it neither prevents redirecting nor pops up the modal.