HTML表单提交问题

Cas*_*ynn 1 html php forms

谁能告诉我为什么这个表单没有正确地向服务器提交值?

  <form method="post" action="http://www.***.com/index.php/session/authenticate" class="form login" id="login_form"> 
    <div class="group wat-cf"> 
      <div class="left"> 
        <label class="label right">Login</label> 
      </div> 
      <div class="right"> 
        <input type="text" class="text_field" id="username"/> 
      </div> 
    </div> 
    <div class="group wat-cf"> 
      <div class="left"> 
        <label class="label right">Password</label> 
      </div> 
      <div class="right"> 
        <input type="password" class="text_field" id="password"/> 
      </div> 
    </div> 
    <div class="group navform wat-cf"> 
      <div class="right"> 
        <button class="button" type="submit"> 
          <img src="images/icons/key.png" alt="Save" /> Login
        </button> 
      </div> 
    </div> 
  </form> 
Run Code Online (Sandbox Code Playgroud)

在服务器端,我回显了$_POST空的超全局,我可以看到在提交表单时发送的请求标头:

Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Content-Length:0
Content-Type:application/x-www-form-urlencoded
Cookie:ci_session=***session_id=***user_agent%22%3Bs%3A50%3A%22Mozilla%2F5.0+%28Macintosh%3B+Intel+Mac+OS+X+10_6_7%29+App%22%3Bs%3A13%3A%22last_activity%22%3Bi%3A1307578661%3B%7D31ee24db2875550081268dc7df883f76; ci_csrf_token=***
Host:www.***.com
Origin:http://**.com
Referer:http://***.com/index.php/session/login
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_7) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/*** Safari/534.30
Run Code Online (Sandbox Code Playgroud)

小智 11

你忘了给输入类型命名,就像这样

<input type="text" class="text_field" name="username" id="username"/> 

<input type="password" class="text_field" name="password" id="password"/> 
Run Code Online (Sandbox Code Playgroud)

  • 不,它们都被使用了.名称用于服务器(字段的实际名称),id用于CSS.该ID不会发送到服务器 (4认同)
  • `name`仅对表单元素之外的大多数元素以及`form`本身不推荐使用.对于`input`元素等,它不被弃用. (2认同)