phpknight Posted August 11, 2007 Share Posted August 11, 2007 I have seen a lot about preventing form submission when somebody hits the enter key. My question is a little different. I usually use an image to submit all forms. Then, when a user clicks, I test using PHP like this: if (isset($_POST['submitButton_x'])) //do this When I have two or more fields, this works just fine whether somebody hits ENTER or clicks the button. It gives button coordinates if it was clicked and 0,0 otherwise. However, when I only have ONE field, if the user clicks enter, it does not register anything for the submitButton_x or y. So, the form essentially does not get submitted at all. Also, putting a second hidden element does not change it. Has anybody else had this issue. If so, how did you fix it? Link to comment https://forums.phpfreaks.com/topic/64406-solved-html-form-image-question/ Share on other sites More sharing options...
NArc0t1c Posted August 12, 2007 Share Posted August 12, 2007 You could try looking for contents in the text field. Example: <html> <head> </head> <body> <form action="script.php" method="post"> <input type="text" name="textbox" value="Data" onclick="this.value=''"> <input type="submit" name="submit" value="submit"> </form> <?php if (empty($_POST['textbox'])){ ?> No data or form not submitted. <?php } else { ?> The form was submitted. <?php } ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/64406-solved-html-form-image-question/#findComment-321841 Share on other sites More sharing options...
phpknight Posted August 12, 2007 Author Share Posted August 12, 2007 I figured out the one text field is definitely as issue. Is there a way to do what you are talking about without that Javascript? Link to comment https://forums.phpfreaks.com/topic/64406-solved-html-form-image-question/#findComment-321871 Share on other sites More sharing options...
NArc0t1c Posted August 13, 2007 Share Posted August 13, 2007 There is no javascript, if you are talking about the php scripting. Then the short answer is no. Link to comment https://forums.phpfreaks.com/topic/64406-solved-html-form-image-question/#findComment-322153 Share on other sites More sharing options...
phpknight Posted August 13, 2007 Author Share Posted August 13, 2007 That onclick thing is not Javascript? Link to comment https://forums.phpfreaks.com/topic/64406-solved-html-form-image-question/#findComment-322188 Share on other sites More sharing options...
NArc0t1c Posted August 13, 2007 Share Posted August 13, 2007 No, It is an HTML Element. Link to comment https://forums.phpfreaks.com/topic/64406-solved-html-form-image-question/#findComment-322190 Share on other sites More sharing options...
ToonMariner Posted August 13, 2007 Share Posted August 13, 2007 ??? onclick is an eventhandler for calling javascript (or vbscript if you are stupid enough to use is). My concern here is that in each case you are trying to override the default behaviour of a browser. My advice would be to use just submit buttons that are styled (MAC's will swap the image input for its own glass button anyway) and let the browser do what ever it does. You will find browsers do NOT handle the image input the same way - some pass the co-ordinates clicked other just the fact it was clicked. So where possible use mark-up that will work on a text-only browser and use css to make it look good. By all means do some js client side checks if you want but ensure you validate ALL user input server side too. Link to comment https://forums.phpfreaks.com/topic/64406-solved-html-form-image-question/#findComment-322202 Share on other sites More sharing options...
phpknight Posted August 13, 2007 Author Share Posted August 13, 2007 Okay, thanks. Link to comment https://forums.phpfreaks.com/topic/64406-solved-html-form-image-question/#findComment-322437 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.