I've tried my code with POST and GET method also, but I can't see any value of these methods. After submit the form the page is refreshing but my .php file write out this: Array ( )
I was looking for the value in Chrome developer tools but there is no 'Form data' inside the network tab, just general, response headers and request headers.
My HTML code:
<!--Modal: Login Form-->
<form id="loginModal" name="loginModal" class="modal fade modal-full-height" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"
data-backdrop="static" action="/main.php" method="POST">
<div class="modal-dialog cascading-modal" role="document">
<!--Content-->
<div id="loginModalDiv" class="modal-content">
<!--Header-->
<div class="modal-header myModalHeader">
<h4 class="title"><i class="fa fa-user-lg"></i> Login:</h4>
</div>
<!--Body-->
<div class="modal-body">
<div class="md-form form-sm">
<i class="fa fa-envelope prefix"></i>
<input type="text" id="logF_email" name="email" class="form-control">
<label for="logF_email">E-mail address:</label>
</div>
<div class="md-form form-sm">
<i class="fa fa-lock prefix"></i>
<input type="password" id="logF_passw" name="password" class="form-control">
<label for="logF_passw ">Password:</label>
</div>
<div class="text-center mt-2">
<div id="errorLogin"></div>
<button id="btnLogin" type="submit" class="btn btn-default myModalBtn">Belépés <i class="fa fa-sign-in ml-1"></i></button>
</div>
</div>
<!--Footer-->
<div id="footerLogin" class="modal-footer">
<div class="options text-center text-md-center mt-1">
<p>You don't have an account? <a class="loginToSignUp myGreenClass" data-toggle="modal" href="#"> Sign up!</a></p>
<p>Forget <a class="forgetPassword myGreenClass" data-toggle="modal" href="#"> password?</a></p>
</div>
<button type="button" class="btn btn-outline-default waves-effect ml-auto myModalBtn" data-dismiss="modal">Close</button>
</div>
</div>
<!--/.Content-->
</div>
</form>
...and the .php file:
$email =""; $password ="";
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
print_r($_POST);
$email = $_POST['email'];
$password = $_POST['password'];
print_r($email);
print_r($password);
if ($email=="") {echo "<br> 'no data'";}
else {echo "Your email: ".$email;}
}
I'm beginner in PHP, and form-handling, so I think I could miss something. I tried to avoid the trivial mistakes, therefor my code contains:
- action and method proprty for form
- name attribute for input fields
type="submit"
for submit button
if ( $_POST ){
if (!empty($_POST)){
also not working
Any idea what's wrong?