-2

This is a simple demonstration of my code :

if(isset($_POST['login'])) {
   do this
}

<form method='POST' action="index.php">
Username : <input type='text' name='username'/>
Password : <input type='password' name='password' />
<input type='image' src='images/login.png' name='login' value='login'/>
</form>

The problem is that , when i use type='image' as a submit button, in Firefox and IE nothing happends. But if i use type='submit' everything works fine..

Well i dont want to display the button as a submit one, but as an image, so what im doing wrong ?

  • If you're willing to use JavaScript you could add an onClick form submit? – Edd Turtle Oct 30 '13 at 17:36
  • what is input type = image ? and how could form gonna know when to submit itself ? and clicking on last input type element in form dosnt mean it will submit form – Prince Singh Oct 30 '13 at 17:38
  • your html code is correct and works fine, @hanky answer's for the solution : wrong POST check – Asenar Oct 30 '13 at 17:40
  • @wordpresser input type=image results as 2 more indexes in the `_POST` array : `$_POST['login_x']` and `$_POST['login_y']`. Their values correspond to the (x,y) coordinate of the mouse from the top left of the picture ( = (0,0) if you press enter)) – Asenar Oct 30 '13 at 17:43
  • let me try that one @ Asenar . thanx for enlightening me – Prince Singh Oct 30 '13 at 17:47
  • And, I noticed some old spam robots don't create theses 2 extra indexes, so this can be an extra check : human user will always post with x and y (even if = 0). __EDIT :__ maybe we should make test on terminal browser to see its behaviour. __EDIT2:__ I confirm, I got `login_x` and `login_y` index with lynx – Asenar Oct 30 '13 at 17:55
  • I made this question , because type='image' used to work as Submit buttons , Google Chrome still supprots this method, IE and Firefox dont. But now im using this : and everything is working just fine , thanks a lot for you answers and for you no votes LOL, i made the question to learn from you and not to get voted haha –  Oct 30 '13 at 18:31
  • Dajan, see my answer who will probably answer your needs ;) – Asenar Oct 30 '13 at 18:49

2 Answers2

3

Simply change your if to look for any other field in the POST. Image type button wont send that value.

Change:

if(isset($_POST['login'])) {  

To

if(isset($_POST['username'])) {
Hanky Panky
  • 46,730
  • 8
  • 72
  • 95
0

If you want to check login, you need to check for login_x or login_y values instead of login, which is not created when button is an image.

<?php
if(isset($_POST['login_x'])) { 
   echo "Here I m";
}
?>
<form method='POST' action="index.php">
Username : <input type='text' name='username'/>
Password : <input type='password' name='password' />
<input type='image' src='images/login.png' name='login' value='login'/>
</form>

Sorry, I explained in a comment the type=image creating _x and _y, but I forgot the params login does not exists in that case

Asenar
  • 6,732
  • 3
  • 36
  • 49