Learner Learner - 1 year ago 110
PHP Question

Bootstrap Modal Form submit error

I know this question has many solutions in SO.But still I cant spot my mistake.The following is my bootstrap modal form

<!DOCTYPE html>
<html lang="en">
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="assets/lib/bootstrap/css/bootstrap.min.css">
<script src="../asset/modal/js/jquery.min.js"></script>
<script src="assets/lib/bootstrap/js/bootstrap.min.js"></script>
<? if(isset($_POST["sendmail"]))
echo "Form 1 have been submitted";
<div class="container">

<!-- Trigger the modal with a button -->

<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<? echo $token; ?>
<!-- Modal content-->
<form class="form-horizontal" role="form" method="post" name="sendmail" >
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Modal Header</h4>
<div class="modal-body">
<textarea rows="8" class="form-control"></textarea>
<div class="modal-footer">
<button type="submit" class="btn btn-default" >Send</button>



But whenever i submit the form it redirects to the index page of my project.Please Help me spotting my error.:-(

Answer Source

Yes its because you are not directing it anywhere...You need to write something like this:-

   <form class="form-horizontal" role="form" method="post" name="sendmail" action="page_name_here.php" >

So you need to add action="page_name_here.php">

If you want to stay on the same page then just write action="#">


 <button type="submit" class="btn btn-default" name="send">Send</button>

Add a name to the button send then in the Php:-

<? if(isset($_POST["send"]))
 echo "Form 1 have been submitted";

This way when you click the send button everything in the form is submitted, since its a button of type=submit

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download