Xurion Posted August 24, 2006 Share Posted August 24, 2006 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]<?phpif($_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! ::) Quote Link to comment Share on other sites More sharing options...
ScottRiley Posted August 24, 2006 Share Posted August 24, 2006 I think the $_POST indicies need to be in quotation marks. Instead of $_POST[submit] you need $_POST['submit'], but I'm not sure ??? Quote Link to comment Share on other sites More sharing options...
ronverdonk Posted August 24, 2006 Share Posted August 24, 2006 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 Link to comment Share on other sites More sharing options...
Xurion Posted August 24, 2006 Author Share Posted August 24, 2006 [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! Quote Link to comment Share on other sites More sharing options...
ronverdonk Posted August 24, 2006 Share Posted August 24, 2006 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) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.