Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Modal Form Submission

Featured Replies

Hi,

 

I'm using materialize.css (http://materializecss.com/modals.html) to display a modal/pop-up Form on page load.

 

I have the modal displaying fine and submitting data via PHP. However, I want the pop-up to just close after submit instead of the user being redirected to another page.

I've tried having it redirect back to the current page but this re-opens the pop-up again.

 

Below is my PHP:

<?php
$email_to = "mail@domain.co.uk";
$name = $_POST["name"];
$email_from = $_POST["email"];
$tel = $_POST["tel"];
$message = $_POST["message"];
$email_subject = "Feedback from website";
$headers = "From: " . $email_from . "\n";
$headers .= "Reply-To: " . $email_from . "\n";


$message = "Name: ". $name . "\r\nTel: " . $tel . "\r\nMessage: " . $message;


ini_set("sendmail_from", $email_from);
$sent = mail($email_to, $email_subject, $message, $headers, "-f" .$email_from);
if ($sent)
{
header("Location: http://domain.co.uk/test.html");
} else {
echo "There has been an error sending your comments. Please try later.";
}
?>

Any help greatly appreciated.

Wasn't sure whether to post in this section or JS so please move if in the wrong place.

Edited by AndyDesigns

I think you are redirecting your user on that page where your popup is located. instead of redirecting to popup page try to redirecting to the main page where you have simple page content. i mean to say try to separate your popup page and redirection page when you want to redirect your user.

Hope it helps...

  • Author

Thats my point though, I don't want to redirect the user at all. I just want them to be able to press submit and then stay on the current page.

You will need to validate and submit the form using Ajax and then fire a callback that closes the modal on success.

Something like this, but you can use vanilla JS if you don't want to include jQuery, you'll have to write that yourself, though. The callback for the modal is:

$('#modal1').modal('close');
  • Author

 

You will need to validate and submit the form using Ajax and then fire a callback that closes the modal on success.

 

Something like this, but you can use vanilla JS if you don't want to include jQuery, you'll have to write that yourself, though. The callback for the modal is:

$('#modal1').modal('close');

 

Thanks I thought Ajax may be the only way. I'll look into it although I'm not every familiar with it.

  • Author

Unfortunately that tutorial doesnt include actually sending the form data to a recipient mail in the PHP. I've tried finding other AJAX Form tutorials but they either don't show you how to process the form data via PHP or dont include a modal.

 

If anyone can point me in the right direction it would be appreciated.

Unfortunately that tutorial doesnt include actually sending the form data to a recipient mail in the PHP. I've tried finding other AJAX Form tutorials but they either don't show you how to process the form data via PHP or dont include a modal.

 

If anyone can point me in the right direction it would be appreciated.

 

In the process.php file, there's a section where you can place the logic if the form validates. You don't have to use this tutorial but the same principles apply.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.