简体   繁体   中英

Php form post method not sending data

I have a simple HTML form, which is actually working well on my localhost and in few servers. But last time I put it in my code, I understood that it doesn't send data with POST , although I have written the method="post" . This is first time I meet this problem, and I don't know if it is from my side or from server. When I dump GLOBAL param $_SERVER in my localhost, the param REQUEST_METHOD is POST , but when I dump it on server it is GET . I also tried to change the method in .htaccess , but no result. Here is my form:

<form action="/auth/login" method="post">
      <div id="error">
            <?
              if (isset($errors)) {
                 foreach ($errors as $error) {
                      echo $error . "<br>";
                  }
               }
               if (isset($invalid)) {
                    echo $invalid;
                }
               ?>
      </div>
      <div id="login-box-name" style="margin-top:20px;">Login:</div>
      <div id="login-box-field" style="margin-top:20px;">
           <input name="login" class="form-login" type="text"/>
       </div>
       <div id="login-box-name">Password:</div>
       <div id="login-box-field">
            <input name="password" type="password" class="form-login"/>
        </div>
        <br />
        <input type="image" src="/images/login-btn.png" width="103" height="42" style="margin-left:90px;" />
   </form>

And on server when I print $_POST or $_POST['login'] they are empty, although I have passed params.

 public function action_login() {  
        echo "<pre>";
        var_dump($_SERVER); // this is returns server data, where REQUEST_METHOD is GET on current server, but POST in my local 
        var_dump($_POST); // this is empty
        echo "</pre>";
}

Is that from server or hosting configuration?

Try this

<form action="auth/login" method="POST">
          <div id="error">
                <?
                  if (isset($errors)) {
                     foreach ($errors as $error) {
                          echo $error . "<br>";
                      }
                   }
                   if (isset($invalid)) {
                        echo $invalid;
                    }
                   ?>
          </div>
          <div id="login-box-name" style="margin-top:20px;">Login:</div>
          <div id="login-box-field" style="margin-top:20px;">
               <input name="login" class="form-login" type="text"/>
           </div>
           <div id="login-box-name">Password:</div>
           <div id="login-box-field">
                <input name="password" type="password" class="form-login"/>
            </div>
            <br />
            <input type="submit" src="/images/login-btn.png" width="103" height="42" style="margin-left:90px;" value="save" />
       </form>

您缺少关键字:type =“ submit”

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM