Jump to content

PHP submit not working


Xurion

Recommended Posts

Hi all.

I posted a problem with this code yesterday, and after it being moved around a bit to different areas of the site, I have come to the conclusion that my problem has something to do with the way my PHP code is submitting.

Simply put, you need to input the numbers that display and click the submit button. If correct you get a message saying they are correct, but if wrong you get a message teling you what the correct sequence was.

The problem is that when you input the number into the text field and press enter/return, the page seems to submit, but it does not execute the code as it should if you clicked the submit button. I tested it in Firefox and it seems to submit fine. Very confused at the moment.


Anyway the code is:

[code]
<?php
if($_POST[submit]){
if($_POST[txtimagenumbers] == $_POST[txtcorrectsequence]){
echo 'correct images!';
} else{
echo 'WRONG! correct sequence was :'.$_POST[txtcorrectsequence];
}
} else{
$codeimages = array('1','2','3','4','5','6'); //names of the images without the .gif extension
$imagenumbers = array(rand(0,5),rand(0,5),rand(0,5),rand(0,5)); //generate the four random numbers deciding on what images to use.
$content = '<html>
<head>
<title>Numbers</title>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td><img src="'.$codeimages[$imagenumbers[0]].'.gif" border="0" alt=""></td>
<td><img src="'.$codeimages[$imagenumbers[1]].'.gif" border="0" alt=""></td>
<td><img src="'.$codeimages[$imagenumbers[2]].'.gif" border="0" alt=""></td>
<td><img src="'.$codeimages[$imagenumbers[3]].'.gif" border="0" alt=""></td>
</tr>
</table>';
$filename = basename($_SERVER['PHP_SELF']);
$content .= '<form action="'.$filename.'" method="post">
<input type="text" name="txtimagenumbers">
<input type="hidden" name="txtcorrectsequence" value="'.$codeimages[$imagenumbers[0]].''.$codeimages[$imagenumbers[1]].''.$codeimages[$imagenumbers[2]].''.$codeimages[$imagenumbers[3]].'">
<input type="submit" value="submit" name="submit">
</form>
</body>
</html>';
echo $content;
}
?>
[/code]

Any help to a n00b would be great!  ::)
Link to comment
https://forums.phpfreaks.com/topic/18526-php-submit-not-working/
Share on other sites

[quote author=ronverdonk link=topic=105465.msg421317#msg421317 date=1156412618]
Use a hidden field in your form, such as:
[code]<input type="hidden" name="_submit" value="1">[/code]

then test this value in your POST array instead of 'submit', such as:
[code]if(isset($_POST['_submit'])){
[/code]

Ronald   8)
[/quote]
Thanks for that Ronald.

Your suggestion of using the hidden field worked, but the previous problems solution still eludes me. Strange how Firefox would submit the form. There are various forms online that I have looked at that use the same code and they work >_<

Thx again!
Link to comment
https://forums.phpfreaks.com/topic/18526-php-submit-not-working/#findComment-79781
Share on other sites

As far as I understand it from people who know more about IE quirks then I do, IE does accept the ENTER key press. But the value of a type=submit field is not passed. Values of type=text and type=hidden do get passed.

I don't know why, but that is also what I experience, sio I always use the hidden field to signal submission.

Ronald  8)
Link to comment
https://forums.phpfreaks.com/topic/18526-php-submit-not-working/#findComment-79782
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.