I have a modal on my page, with a contact form in it. Anyway, the fields like mail should be required but it just sends it right away, even when the fields aren't filled in... How is that possible?
The Modal:
<div class="modal fade" id="form-content" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header" style="border-bottom: none;">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Contact</h4>
</div>
<div class="modal-body">
<form class="contact" name="contact">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-user"></i></span>
<input type="text" name="name" class="form-control" placeholder="Name" required="required">
</div>
<br/>
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-envelope"></i></span>
<input type="email" name="email" class="form-control" placeholder="Mail">
</div>
<br/>
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-globe"></i></span>
<input type="url" name="website" class="form-control" placeholder="Website">
</div>
<br/>
<textarea rows="6" name="message" class="form-control" placeholder="Message"></textarea>
</form>
</div>
<div class="modal-footer" style="border-top: none;">
<input class="btn btn-success" type="submit" value="Send!" id="submit">
</div>
</div>
</div>
</div>
PHP script:
<?php
$myemail = 'mail#mail.nl';
if (isset($_POST['name'])) {
$name = strip_tags($_POST['name']);
$email = strip_tags($_POST['email']);
$message = strip_tags($_POST['message']);
$website = strip_tags($_POST['website']);
echo "<br><span style=\"display:table; margin:0 auto;\" class=\"alert alert-success\" id=\"alert-message\" data-alert=\"alert\">Your message has been received. Thank you!</span>";
$to = $myemail;
$email_subject = "Contact formulier van: $name";
$email_body = "Je hebt een nieuw bericht ontvangen via het contactformulier. ".
"Hier zijn de de details:\n Naam: $name \n ".
"Email: $email\n Website: $website \n Bericht: \n $message";
$headers = "From: $email\n";
$headers .= "Reply-To: $email";
mail($to,$email_subject,$email_body,$headers);
}?>
EDIT:
I also hava a main.js, to show the people the form has been sended:
$(document).ready(function () {
$("input#submit").click(function(){
$.ajax({
type: "POST",
url: "process.php", //
data: $('form.contact').serialize(),
success: function(msg){
$("#thanks").html(msg)
$("#form-content").modal('hide');
$('#thanks').delay(3000).fadeOut()
},
error: function(){
alert("failure");
}
});
});
});
You missed the action and method in your form: action="yourpage.php" method="POST"
Where action refers to your php page and method to the way you send data, in this case POST as in your PHP code you have $_POST['name'] (etc).
Also the Submit should be inside the Form tag, not outside.
Something like this:
<div class="modal fade" id="form-content" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header" style="border-bottom: none;">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Contact</h4>
</div>
<div class="modal-body">
<form class="contact" name="contact">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-user"></i></span>
<input type="text" name="name" class="form-control" placeholder="Name" required="required">
</div>
<br/>
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-envelope"></i></span>
<input type="email" name="email" class="form-control" placeholder="Mail">
</div>
<br/>
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-globe"></i></span>
<input type="url" name="website" class="form-control" placeholder="Website">
</div>
<br/>
<textarea rows="6" name="message" class="form-control" placeholder="Message"></textarea>
<div class="modal-footer" style="border-top: none;">
<input class="btn btn-success" type="submit" value="Send!" id="submit">
</div>
</form>
</div>
</div>
</div>
Ref: http://www.w3schools.com/tags/tag_form.asp
You have to mention form method and action in form open tag. After then check the output.
for example, Form structure should be like,
<form name="input" action="demo_form_action.asp" method="get">
Username: <input type="text" name="user">
<input type="submit" value="Submit">
</form>
Related
I have created an Edit Item popup Bootstrap modal on home page. Now what I want is to update the selected item details using the PHP.
Here i am passing item id through the URL in order to select the item
Now when I press edit Button it opens a Popup with all the details in it( already filled) but when I try to click on Save Changes Button it just do nothing and My data not updated. I have also used POST method but its not working.
Here is the Button that opens the Popup Modal
<?php
$res= mysqli_query($db,"SELECT* FROM `books`;");
if(mysqli_num_rows($res)>0){
while($row= mysqli_fetch_assoc($res)){
if($row!=0)
{
$bid= $row['book_id'];
?>
<ul>
<li>
<a onclick="$('#editModal<?php echo $row['book_id']?>').modal('show');" class="btn-show-modal edit-btn" data-toggle="modal"><i style="padding-right: 140px;" class="fas fa-edit"></i></a>
</li>
<!--Here is the Popup Modal for Edit -->
<div id="editModal<?php echo $row['book_id']?>" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Edit This Book</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form action="updatebook.php" method="POST">
<div class="form-group">
<label for="isbn" class="col-form-label">ISBN</label>
<input type="text" class="form-control" name="isbn" value="<?php echo $row['isbn'];?>">
</div>
<div class="form-group">
<label for="title" class="col-form-label">Enter Book Title</label>
<input type="text" class="form-control" name="title" value="<?php echo $row['title'];?>">
</div>
<div class="form-group">
<label for="author" class="col-form-label">Enter Author Name</label>
<input type="text" class="form-control" name="author" value="<?php echo $row['author'];?>">
</div>
<div class="form-group">
<label for="image" class="col-form-label">Image URL</label>
<input type="text" class="form-control" name="image" value="<?php echo $row['image'];?>">
</div>
<div class="form-group">
<label for="description" class="col-form-label">Enter Book Description</label>
<textarea class="form-control" name="description" value="<?php echo $row['description'];?>"></textarea>
</div>
<div class="form-group">
<label for="url" class="col-form-label">Book URL</label>
<input type="text" class="form-control" name="url" value="<?php echo $row['url'];?>"></textarea>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" name="save">Save Changes</button>
</div>
</div>
</div>
</div>
<?php
}
}
}
else
{
echo"<h1 style='color: white;font-size:58px; font-family: Poppins; font-weight: 600;' class=m-2>U!Oh Nothing Found Here!</h1>
<button onclick=\"window.location.href='add_books_form.php'\" class=\"btn btn-info bg-primary m-5\">Contribute</button>";
}
?>
</ul>
Here is the updatebook.php Page
<?php
include "connection.inc.php";
if(isset($_POST['save']))
{
$id= $_POST['id'];
$isbn= $_POST['isbn'];
$title= $_POST['title'];
$author= $_POST['author'];
$image= $_POST['image'];
$desc= $_POST['description'];
$url= $_POST['url'];
$res = mysqli_query($db, "UPDATE books SET isbn= '$isbn', title= '$title', author= '$author',image= '$image', description= '$desc', url= '$url' WHERE book_id= '$id'");
?>
if($res)
{
<script type="text/javascript">
alert("Data Updated Successfully");
window.location.href= "home.php";
</script>
}
else
{
<script>
alert("Not Updated!");
window.location.href="home.php";
</script>
}
<?php
}
?>
Please Help me to solve this Update Issue i am facing for a long time. I have researched all through but didn't got any solution.
Change your Save button type to "submit" and remove the <a> hyperlink.
Use <form> as a part of both modal-body and modal-footer so the submit button will be part of it.
Take book_id in a hidden field so it will be the part of POST.
Look at the modal code below:
<div id="editModal<?php echo $row['book_id']?>" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Edit This Book</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<form action="updatebook.php" method="POST">
<input type="hidden" name="id" value="<?php echo $row['book_id'];?>">
<div class="modal-body">
<div class="form-group">
<label for="isbn" class="col-form-label">ISBN</label>
<input type="text" class="form-control" name="isbn" value="<?php echo $row['isbn'];?>">
</div>
<div class="form-group">
<label for="title" class="col-form-label">Enter Book Title</label>
<input type="text" class="form-control" name="title" value="<?php echo $row['title'];?>">
</div>
<div class="form-group">
<label for="author" class="col-form-label">Enter Author Name</label>
<input type="text" class="form-control" name="author" value="<?php echo $row['author'];?>">
</div>
<div class="form-group">
<label for="image" class="col-form-label">Image URL</label>
<input type="text" class="form-control" name="image" value="<?php echo $row['image'];?>">
</div>
<div class="form-group">
<label for="description" class="col-form-label">Enter Book Description</label>
<textarea class="form-control" name="description" value="<?php echo $row['description'];?>"></textarea>
</div>
<div class="form-group">
<label for="url" class="col-form-label">Book URL</label>
<input type="text" class="form-control" name="url" value="<?php echo $row['url'];?>"></textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" name="save">Save Changes</button>
</div>
</form>
</div>
</div>
</div>
I have index.php file which stores a form for user signup. But whenever I try to display data that is stored in the serializeArray it says that it is empty. Here is my code for the html form:
<form method="post" id="signupForm">
<div class="modal fade" id="signupModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="signupModalLabel">Sign Up</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="alert alert-danger" id="signupAlert" role="alert">
This is a danger alert—check it out!
</div>
<div class="form-group">
<label for="username">Username</label>
<input type="text" class="form-control" id="username" placeholder="Username" maxlength="30">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" class="form-control" id="email" placeholder="Email address" maxlength="50">
</div>
<div class="form-group">
<label for="password">Choose a Password</label>
<input type="password" class="form-control" id="password" placeholder="Password" maxlength="30">
</div>
<div class="form-group">
<label for="passwordConfirm">Confirm Password</label>
<input type="password" class="form-control" id="passwordConfirm" placeholder="Confirm Password" maxlength="30">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<input class="btn btn-primary" name="signup" type="submit" class="btn btn-primary" value="Sign Up">
</div>
</div>
</div>
</div>
</form>
In my index.js I have a function to take all form fields entered and store them in serializeArray.
$("#signupForm").submit(function(event){
event.preventDefault();
var data = $(this).serializeArray(data);
console.log(data)
})
The array results shows that there are no values. I have tried to console log any string to see if I have correctly linked my index.js file to index.php and it works. There is only problem with getting form fields into the array.
[]length: 0 proto: Array(0)
<div class="col-lg-10 col-lg-offset-1 text-center">
<form method="POST" action="index.php" accept="text/html" formenctype="multipart/form-data" class="contact-form row">
<div class="col-md-4">
<label></label>
<input name="name" type="text" class="form-control" placeholder="Name">
</div>
<div class="col-md-4">
<label></label>
<input name="email" type="text" class="form-control" placeholder="Email">
</div>
<div class="col-md-4">
<label></label>
<input name="subject" type="text" class="form-control" placeholder="Subject">
</div>
<div class="col-md-12">
<label></label>
<textarea name="message" class="form-control" rows="9" placeholder="Your message here.."></textarea>
</div>
<div class="col-md-4 col-md-offset-4">
<label></label>
<button id="submit" name="submit" type="sumbit" data-toggle="modal" data-target="#alertModal" class="btn btn-primary btn-block btn-lg">Send <i class="ion-android-arrow-forward"></i></button>
</div>
</form>
</div>
</div>
</div>
</section>
<div id="alertModal" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-body">
<h2 class="text-center">Submitted sucessfully!</h2>
<p class="text-center">You clicked the button</p>
<br/>
<button class="btn btn-primary btn-lg center-block" data-dismiss="modal" aria-hidden="true">OK <i class="ion-android-close"></i></button>
</div>
</div>
</div>
</div>
<?php
$headers = ''; // added this line
$headers. = "MIME-Version: 1.0\r\n";
$headers. = "Content-type: text/html\r\n";
$headers = 'From: $name'.
"\r\n". // added .= instead of =
'X-Mailer: PHP/'.phpversion();
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: '.$email;
$to = 'random#gmail.com';
$subject = $_POST['subject'];
$body = " From: $name\n E-mail: $email\n Subject: $subject\n Message:\n $message";
if (isset($_POST['submit'])) {
/* Anything that goes in here is only performed if the form is submitted */
if (mail('random#gmail.com', $subject, $body, $from)) {
echo "<script type='text/javascript'>$(document).ready(function(){ $('#alertModal').modal('show');});</script>";
} else {
echo "something went wrong";
}
} ?>
I have been trying to call my modal when submitting my form, but cannot seem to get it to work.
I have been looking at various different questions but nothing seems to work.
I do not have JS for this and my PHP is incorporated on a separate page.
Please help, I want the modal to open on the same page as the form when someone submits the info.
Thanks
See , it is working
function showModal(){
$('#alertModal').modal('show');
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="col-lg-10 col-lg-offset-1 text-center">
<form method="POST" action="index.php" accept="text/html" formenctype="multipart/form-data" class="contact-form row">
<div class="col-md-4">
<label></label>
<input name="name" type="text" class="form-control" placeholder="Name">
</div>
<div class="col-md-4">
<label></label>
<input name="email" type="text" class="form-control" placeholder="Email">
</div>
<div class="col-md-4">
<label></label>
<input name="subject" type="text" class="form-control" placeholder="Subject">
</div>
<div class="col-md-12">
<label></label>
<textarea name="message" class="form-control" rows="9" placeholder="Your message here.."></textarea>
</div>
<div class="col-md-4 col-md-offset-4">
<label></label>
<button id="submit" name="submit" type="sumbit" data-toggle="modal" data-target="#alertModal" class="btn btn-primary btn-block btn-lg">Send <i class="ion-android-arrow-forward"></i></button>
</div>
</form>
</div>
</div>
</div>
</section>
<div id="alertModal" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-body">
<h2 class="text-center">Submitted sucessfully!</h2>
<p class="text-center">You clicked the button</p>
<br/>
<button class="btn btn-primary btn-lg center-block" data-dismiss="modal" aria-hidden="true">OK <i class="ion-android-close"></i></button>
</div>
</div>
</div>
</div>
<?php
$headers = ''; // added this line
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html\r\n";
$headers = 'From: $name' . "\r\n" . // added .= instead of =
'X-Mailer: PHP/' . phpversion();
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: ' . $email;
$to = 'random#gmail.com';
$subject = $_POST['subject'];
$body = " From: $name\n E-mail: $email\n Subject: $subject\n Message:\n $message";
if (isset($_POST['submit']))
{
/* Anything that goes in here is only performed if the form is submitted */
if (mail ('random#gmail.com', $subject, $body, $from ))
{
echo "<script type='text/javascript'>showModal();</script>";
} else
{
echo "something went wrong";
}
}
?>
you have two choice
change button type:
<button type="button" class="btn btn-primary btn-lg center-block" data-dismiss="modal" aria-hidden="true">OK <i class="ion-android-close"></i></button>
call function:
<form method="POST" action="index.php" accept="text/html" formenctype="multipart/form-data" class="contact-form row" onSubmit="show_modal();return;">
and the function:
function show_modal(){
$('#myModal').modal('show');
}
UPDATE (requested in comments)
Set timer for submit form after delay:
Change button type to button: type="button"
add this code to your page:
$("#submit").click(function(){
setTimeout(function() {
$("form").submit();
}, 5000); // 5 sec
$("#myModal").show(); //Find your modal id and replace with myModal
});
Note: don't forget to include jquery lib
My modal is not showing. the page is reloading and then i receive an email.
Below you can find my code. Can somebody help me out please... I think the problem is that my page is reloading after clicking the submit button.
Below my form that i use :
<form id="form" method="post" name="form" autocomplete="on">
<div class="row">
<div class="col-sm-6 nopadding-right">
<div class="input-group">
<div class="input-group-addon"><span class="fa fa-user"></span></div>
<input type="text" name="vname" placeholder="Name" class="form-control requiredField name" value="" />
</div>
<div class="input-group">
<div class="input-group-addon"><span class="fa fa-phone"></span></div>
<input type="text" name="vphone" placeholder="Phone" class="form-control requiredField phone" value="" />
</div>
<div class="input-group">
<div class="input-group-addon"><span class="fa fa-at"></span></div>
<input type="email" name="vmail" placeholder="Enter email" class="form-control requiredField email" value="" />
</div>
</div>
<div class="col-sm-6">
<div class="input-group mail-block">
<div class="input-group-addon"><span class="fa fa-pencil"></span></div><textarea class="form-control message" name="vtext" placeholder="Message" rows="4"></textarea><input class="btn btn-primary inverse-btn" id="send" name="confirm" type="submit" value="send">
</div>
</div>
</div>
</form>
The modal :
<div class="modal fade" id="Modal" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Thank you</h4>
</div>
<div class="modal-body">
<p>Thanks for getting in touch!</p>
</div>
</div>
</div></div>
My php code :
<?php if(isset($_POST["confirm"])){ if($_POST["vname"]==""||$_POST["vmail"]==""||$_POST["vphone"]==""||$_POST["vtext"]==""){
echo "error";}else{
$email=$_POST['vmail'];
$email =filter_var($email, FILTER_SANITIZE_EMAIL);
$email= filter_var($email, FILTER_VALIDATE_EMAIL);
if (!$email){
echo "error";
}
else{
$subject = "mail " . $_POST['vname'];
$message = $_POST['vtext'] . "\r\n" . ' phone ' . $_POST['vphone'] ."\r\n" . $_POST['vmail'];
$headers = 'From:'. "xxx#email.com" . "\r\n"; // Sender's Email
$headers .= 'Cc:'. "xxx#email.com" . "\r\n"; // Carbon copy to Sender
$message = wordwrap($message, 70);
mail("xxx.yy#xxx.com", $subject, $message, $headers);
echo "<script type='text/javascript'>
$(document).ready(function(){
$('#Modal').modal('show');
});
</script>";
}
}
}?>
The remedy is to use AJAX call instead of form submission. It allows you to do better error handling as well.
I am working on a site, and having never done something like this, I am unsure how to proceed with PHP. I am working with bootstrap and looking to send an email based on a modal. My HTML looks like
<div class="modal fade" id="contact" role="dialoge">
<div class="modal-dialog">
<div class="modal-content">
<form class="form-horizontal">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4>Plan your Party!</h4>
</div>
<form class="name" name="contact">
<div class="modal-body">
<div class="form-group">
<label for="name" class="col-lg-2 control-label">Name:</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="name" required="required" placeholder="Full Name">
</div>l
</div>
<div class="form-group">
<label for="email" class="col-lg-2 control-label">Email:</label>
<div class="col-lg-10">
<input type="email" class="form-control" name="email" required="required" placeholder="Email">
</div>
</div>
<div class="form-group">
<label for="message" class="col-lg-2 control-label">Message:</label>
<div class="col-lg-10">
<textarea class="form-control" rows="8" style="resize: vertical;" required="required" placeholder="Message" name="message"></textarea>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-info" data-dismiss="modal"><i class="glyphicon glyphicon-remove"></i> Close</button>
<button class="btn btn-success" type="submit" id="submit"><i class="glyphicon glyphicon-inbox"></i> Submit</button>
</div>
</div>
</div>
</div>
So I am just wondering if anyone could give me some pointers to make this form actually send the email. I am looking to learn and willing to try anything. Thanks in advance, help and constructful criticism appreciated. Also, how would I approach adding a confirmation that the message has been sent?
Thanks, John.
<script>
$(document).ready(function () {
$("input#submit").click(function(){
$.ajax({
type: "POST",
url: "process.php", //
data: $('form.contact').serialize(),
success: function(msg){
$("#thanks").html(msg)
$("#form-content").modal('hide');
},
error: function(){
alert("failure");
}
});
});
});
</script>
This is the script I tried to add to call the php:
<?php
$myemail = 'myemail#myemail.ca';
if (isset($_POST['name'])) {
$name = strip_tags($_POST['name']);
$email = strip_tags($_POST['email']);
$message = strip_tags($_POST['message']);
echo "<span class=\"alert alert-success\" >Your message has been received. Thanks! Here is what you submitted:</span><br><br>";
echo "<stong>Name:</strong> ".$name."<br>";
echo "<stong>Email:</strong> ".$email."<br>";
echo "<stong>Message:</strong> ".$message."<br>";
$to = $myemail;
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. ".
" Here are the details:\n Name: $name \n ".
"Email: $email\n Message \n $message";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email";
mail($to,$email_subject,$email_body,$headers);
}
?>
And I mean I am sure there is something I am missing, or some simple fix, this is all just so new to me.
Following are the edits for you:
1) You have two forms in the modal and none of them having closing form tag. Remove <form class="form-horizontal"> form and change your other form to <form class="contact">
2) Give closing form tag.
3) Change submit button to <button class="btn btn-success" id="submit"><i class="glyphicon glyphicon-inbox"></i> Submit</button>
4) Also check updated AJAX code and PHP code.
Hope this should help you..
HTML
<div id="thanks"> </div>
<p>
<a data-toggle="modal" href="#contact"
class="btn btn-primary">Contact us</a>
</p>
<!-- model content -->
<div class="modal hide fade in" style="display: none; " id="contact" >
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4>Plan your Party!</h4>
</div>
<form class="contact">
<div class="modal-body">
<div class="form-group">
<label for="name" class="col-lg-2 control-label">Name:</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="name" required="required" placeholder="Full Name">
</div>
</div>
<div class="form-group">
<label for="email" class="col-lg-2 control-label">Email:</label>
<div class="col-lg-10">
<input type="email" class="form-control" name="email" required="required" placeholder="Email">
</div>
</div>
<div class="form-group">
<label for="message" class="col-lg-2 control-label">Message:</label>
<div class="col-lg-10">
<textarea class="form-control" rows="8" style="resize: vertical;" required="required" placeholder="Message" name="message"></textarea>
</div>
</div>
</div>
</form>
<div class="modal-footer">
<button type="button" class="btn btn-info" data-dismiss="modal"><i class="glyphicon glyphicon-remove"></i> Close</button>
<button class="btn btn-success" id="submit"><i class="glyphicon glyphicon-inbox"></i> Submit</button>
</div>
</div>
</div>
</div>
AJAX
<script>
$(function() {
//twitter bootstrap script
$("button#submit").click(function(){
$.ajax({
type: "POST",
url: "process.php",
data: $('form.contact').serialize(),
success: function(msg){
$("#thanks").html(msg);
$("#contact").modal('hide');
},
error: function(){
alert("failure");
}
});
});
});
</script>
process.php
<?php
$myemail = 'myemail#myemail.ca';
if (isset($_POST['name']))
{
$name = strip_tags($_POST['name']);
$email = strip_tags($_POST['email']);
$message = strip_tags($_POST['message']);
$msg_success = "";
$msg_fail = "Error sending mail.";
$msg_success .= "<span class=\"alert alert-success\" >Your message has been received. Thanks! Here is what you submitted:</span><br><br>";
$msg_success .= "<stong>Name:</strong> ".$name."<br>";
$msg_success .= "<stong>Email:</strong> ".$email."<br>";
$msg_success .= "<stong>Message:</strong> ".$message."<br>";
$to = $myemail;
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. ".
" Here are the details:\n Name: $name \n ".
"Email: $email\n Message \n $message";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email";
if(mail($to,$email_subject,$email_body,$headers))
echo $msg_success;
else
echo $msg_fail;
}
else
echo "Input parameters missing";
?>
In form tag include action attribute to point any PHP page, from there you can send emails...