0

I am using default contact form available in D7 under module section. The problem is that contact form redirects to the homepage. It doesn't show any information about submission, such as "Your message has been sent" etc etc. Instead it redirects to home page immediately.

I don't want the contact form to redirect. It should stay here and should show the submission information/message.

2 Answers 2

1

You can use hook_form_alter to hook into the contact form and change the default submit behaviour. So instead of redirecting when the form submits, you can just omit that part and display the status message.

function mymodule_form_alter($form, &$form_state, $form_id ) {
  if ($form_id == 'contact_site_form') {
    // Use our own custom submit function for the contact form.
    $form['#submit'] = array('my_custom_submit');
  }
}

function my_custom_submit($form, &$form_state) {
  drupal_set_message(t('Success.'));
}
4
  • Can you please provide me the code ? Or more details please?
    – ravi
    Commented Aug 18, 2017 at 13:23
  • See code added above
    – SN_26
    Commented Aug 18, 2017 at 13:31
  • How about the submission message/notification ? Actually I doubt myself that probably as per my configurations the message is not being displayed. Though I am not sure.
    – ravi
    Commented Aug 18, 2017 at 13:36
  • Not sure what you mean exactly. Without seeing much code or examples it's really hard to determine what your trying to do. But you can add your custom notification/message using drupal_set_message() in the submit function.
    – SN_26
    Commented Aug 18, 2017 at 13:40
0

At least you can make sure that a message displays with the help of Rules module.

Creating a rule that will display a message on the site when a contact form it submitted...

It's a start.

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.