tags:

views:

51

answers:

5

This is a piece of code on home.php

<form action="./Login" method="post">
Email Address: <br />
<input type="text" name="username" tabindex="1" /><br />
Password: <br />
<input type="password" name="password" tabindex="2" /><br />
<input type="hidden" name="home" value="yes" />
<div class="options">
<input type="submit" value="" name="LoginCheck" class="submit_n" />
</div>
</form>

On submitting isset($_POST['LoginCheck']) on login.php return false.

I usually write the form part & processing part on the same file & then this seems to work correctly. However for this case i.e processing on other page this does not seem to work.

This is probably a minor problem but what am I doing wrong?

+1  A: 

No value for the LoginCheck submit input. Per PHP docs isset "Determine if a variable is set and is not NULL"

Dustin Laine
But won't that return true for the `isset` call? It's set, but has no value.
aularon
@aularon correct it should still return true
Galen
@aularon: I've (implicitly) addressed that in my own answer.
R. Bemrose
A: 

I think there should be written action="../login.php" instead action="./login.php"

Ricky Dang
What made you think so?
aularon
Gaurav
then Gourav once u write u r full action path..it seems like a bug in u r action path..try with full action path..but u said u r reaching to u r action page..then check u r action page with print_r($_POST) it will help u to check the post values
Ricky Dang
But in u r code above the submit button has nothing to post any value..so give the submit button any value or remove value=""
Ricky Dang
A: 

The answer is simple:

Remove the value=""

Web browsers are not required to submit controls that don't have values:

If a control doesn't have a current value when the form is submitted, user agents are not required to treat it as a successful control.

--HTML4 spec, Section 17.13.2 Successful Controls

To clarify, web browsers are required to submit only successful controls, meaning that if the browser opted not to treat the control as successful, the browser can't submit the control.

A successful control is "valid" for submission.

--HTML4 spec, same section as above

R. Bemrose
Nope, still does not work. Not only does removing it not help, but know it also shows Submit text on my button which is an image. The value="" ensures that nothing is printed on the button.
Gaurav
A: 

What basically happens is that because you have the value of "LoginCheck" set to "", which is NOTHING, the browser doesn't even send it.

I think if you do a print_r($_POST), you won't even see there as an array key, which is why your isset() fails.

Give it a proper value if you want to do something with it.

Coach John
Gaurav
So you basically imply, that it is impossible to post empty values?
softcr
How come the same code works when:if(isset($_POST['LoginCheck'])){//process code}else{//show form}
Gaurav
Not impossible to post empty values, but don't count on them ;)
Coach John
Why not use a hidden field with a value of 1? Do you do some other logic if that button was specifically pressed?
Coach John
<input type="hidden" name="home" value="yes" />as you can see I tried this. Still does not work. No data gets transferred to the other page.
Gaurav
+1  A: 

I got this working. I have no clue why this worked? Kindly Explain!!

By default all directory access is to index.php [As configured by me in Apache]

So when I say action="./Login" it would go the index.php but for some reason wont remember where it cam from so the POST data isn't there.

I changed it to action="./Login/index.php" & now everything works fine. WHY??????

Gaurav
Cuz the browser will try to post to `/Login`, the server knows it's a directory, will redirect the browser to `/Login/`, on the redirect, the browser won't do the post again. Adding a slash to the action should be enough. and BTW! why didn't you set the action to the full path of the action page from the start!
aularon