0

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.

enter image description here

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?

10
  • 1
    change method="GET" to method="post" Commented Feb 15, 2018 at 11:00
  • It is post, i just try get and post also. Commented Feb 15, 2018 at 11:04
  • none of them work Commented Feb 15, 2018 at 11:04
  • I mean if i change in php and html to post Commented Feb 15, 2018 at 11:05
  • all the answers below are exactly the same ;) Commented Feb 15, 2018 at 11:06

4 Answers 4

3

Change your form method from GET to POST as your backend is filtering on the POST method.

Sign up to request clarification or add additional context in comments.

1 Comment

I've tried post and get, and forget to set back, by the way none of them working
2

In your form tag method is GET it should be POST. If you do not mention method it will take GET method automatically. So you want get data from POST then you should use POST method in form tag. Remove GET from the form tag.

<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">

4 Comments

I've tried post and get, and forget to set back, by the way none of them working
are you click back button after form submission?
What exactly you want to achieve?
On the form there are two inputs for email and password. I validated them in javascript, and I want to do the same in php then check it in database. Actually a complete login and signup procedure for a web app.
1

Change the method of the form to post in place of get

method="GET"

to

method="post"

As in backend you looking for request method as post. In frontend and backend both needs to be same.

1 Comment

I've tried post and get, and forget to set back, by the way none of them working
0

Okay guys, I've found the error!

Before I sent the value I validated the data with jQuery inside the submit function.

$("#loginModal").submit(function(){
...

The problem is that I've disabled the form before submitting it because I wanted to make some precautionary measure to the user won't be able to do anything until the server not respond.
(e.g.: long waiting time if the connection is slow)

...
$('#loginModalDiv *').prop('disabled',true);
$('#footerLogin').hide();
return true;}

When I cut the last two line out before the return, (so the form stay enabled) the submit function became capable to send the data from the input fields.

Conclusion:
So,... for everybody who don't know (like me before), the POST and GET method not send any data from a disabled part(like a < div >) of a form. Hmmm... good to know! :)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.