Can anyone tell me why this form does not properly submit values to server?
<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>
On the server side I echo out the $_POST superglobal which is empty, and I can see my request headers which are sent when the form is submitted:
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
Kevin Ji
10.5k4 gold badges43 silver badges65 bronze badges
asked Jun 9, 2011 at 0:27
Casey Flynn
14.1k26 gold badges109 silver badges197 bronze badges
-
Does the HTML validate? Could there be two nested forms?Pekka– Pekka2011年06月09日 00:30:36 +00:00Commented Jun 9, 2011 at 0:30
-
sure about that action url ??user557846– user5578462011年06月09日 00:30:51 +00:00Commented Jun 9, 2011 at 0:30
-
Do you var_dump $_POST or $_POST['']? Because that looks correct. Also, you should use var_dump or print_r as the $_POST is an arrayColum– Colum2011年06月09日 00:31:02 +00:00Commented Jun 9, 2011 at 0:31
-
I'm just commenting out the action url for security purposes, the actual form has the proper action url which is confirmed by the output from my php script on the serverCasey Flynn– Casey Flynn2011年06月09日 00:31:31 +00:00Commented Jun 9, 2011 at 0:31
-
insecure to give us the url of a site on the internet, there must be a lot of insure sits out there then :-)user557846– user5578462011年06月09日 00:33:19 +00:00Commented Jun 9, 2011 at 0:33
3 Answers 3
You forgot to give the name for the input type, like this
<input type="text" class="text_field" name="username" id="username"/>
<input type="password" class="text_field" name="password" id="password"/>
Sign up to request clarification or add additional context in comments.
4 Comments
Casey Flynn
I thought using 'name' was deprecated in favor of 'id'?
Colum
No, they are both used. Name is for the server (the actual name of the field), id is used for CSS. The ID is not sent to the server
Abel Mohler
name is not deprecated for form elements.
Kevin Ji
name is only deprecated for most elements outside of form elements, and on form itself. It is not deprecated for input elements and the like.You input tags have no name attribute. I think you are using id's instead of name's
For instance
<input type="text" class="text_field" id="username"/>
should be
<input type="text" class="text_field" id="username" name="username" />
or simply
<input type="text" class="text_field" name="username"/>
if you are not using the id's for anything else.
answered Jun 9, 2011 at 0:33
Nico Burns
17.1k10 gold badges43 silver badges56 bronze badges
Comments
It's the name attribute of input elements that's submitted on the form. Use name='username', etc.
answered Jun 9, 2011 at 0:36
Kevin Nelson
7,7134 gold badges34 silver badges42 bronze badges
Comments
default