Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Kristina Rajic
30 PointsHow to tell form NOT to reload page but open modal window?
Hello guys!
I have quick question, how can I make this form not open new page and change content but instead open modal window, like overlay effect (I would write css, no problem with that, I just need it not to reload page)
<?php
$action=$_REQUEST['action'];
if ($action=="") /* display the contact form */
{
?>
<form action="" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
<div><input name="name" type="text" placeholder="Please input your name..."></div>
<div><input name="email" type="text" placeholder="Please input your e-mail..."></div>
<div><input type="submit" value="Request free e-catalogue"></div>
</form>
<?php
}
else /* send the submitted data */
{
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
if (($name=="")||($email==""))
{
echo "All fields are required, please fill <a href=\"\">the form</a> again.";
}
else{
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Message sent using your contact form";
mail("my@email.com", $subject, $from);
echo "Email sent!";
}
}
?>
1 Answer
Andrew McCormick
17,730 PointsHijack the submit button...
$("form").on('submit', function(e) {
e.preventDefault();
e.returnValue = false;
// do things
});