Rottingham Posted July 14, 2008 Share Posted July 14, 2008 This is one of those bazaar problems that you wrack your brain over and can't figure out, only to realize it's incredibly stupid and simple! I have a form for searching customers in a custom app for a security company. Strangely, when you enter some text into the keywords field and hit enter, it returns to the search form page, meaning the script doesn't realize it is a submission. It knows this by checking if( isset( $_REQUEST["submit"] ) ) .... When you enter the text and click the Search button, it works perfectly. When hitting enter in the text field, it acts like $_REQUEST doesn't receive the form. The code is like such: ( although switch( $_REQUEST["page"] ) { case "search": handle_search(); break; default: break; } function handle_search() { // Form submission or form request if( isset( $_REQUEST["submit"] ) ) { // Handle form // Show results } else { $content = $search_form; } echo $content; } Again, if you hit enter in the form field, the $_REQUEST["submit'] isn't there! When you click the form submit button, it works! Very odd. Quote Link to comment https://forums.phpfreaks.com/topic/114748-form-submission-fails-when-hitting-enter-instead-of-clicking-submit-button/ Share on other sites More sharing options...
rhodesa Posted July 14, 2008 Share Posted July 14, 2008 yeah...that button won't be sent if it's not clicked. is the form method GET or POST? Quote Link to comment https://forums.phpfreaks.com/topic/114748-form-submission-fails-when-hitting-enter-instead-of-clicking-submit-button/#findComment-590041 Share on other sites More sharing options...
.josh Posted July 15, 2008 Share Posted July 15, 2008 maybe I'm not doing it the right or proper way, but I never do an initial check to see if the submit value is there or not. I mean, you're gonna be checking fields anyway, right? So just cut to the chase and look for them first. Or just do a blanket if($_POST) or if($_REQUEST). Quote Link to comment https://forums.phpfreaks.com/topic/114748-form-submission-fails-when-hitting-enter-instead-of-clicking-submit-button/#findComment-590044 Share on other sites More sharing options...
rhodesa Posted July 15, 2008 Share Posted July 15, 2008 i was asking cus i usually do a if($_SERVER['REQUEST_METHOD'] == 'POST'){ but if it's a GET form, you will want to do a if(isset($_GET['search_field'])){ Quote Link to comment https://forums.phpfreaks.com/topic/114748-form-submission-fails-when-hitting-enter-instead-of-clicking-submit-button/#findComment-590045 Share on other sites More sharing options...
Rottingham Posted August 1, 2008 Author Share Posted August 1, 2008 The METHOD is POST. I'm just stumped because I have multiple apps that use the same backend technology and so far this is the only one with this problem. Quote Link to comment https://forums.phpfreaks.com/topic/114748-form-submission-fails-when-hitting-enter-instead-of-clicking-submit-button/#findComment-605580 Share on other sites More sharing options...
deansatch Posted August 1, 2008 Share Posted August 1, 2008 can you post your html code with the button on it? It is the only button on the page isn't it? Quote Link to comment https://forums.phpfreaks.com/topic/114748-form-submission-fails-when-hitting-enter-instead-of-clicking-submit-button/#findComment-605590 Share on other sites More sharing options...
GingerRobot Posted August 1, 2008 Share Posted August 1, 2008 Yes, that's correct. If you press enter to submit a form in IE, the submit button will not be set. It will in firefox. You should do something like this to check if a form has been submitted: if(count($_POST) > 0){ //form is submitted } Edit: Or, as CV suggested, you can do: if($_POST){ } Quote Link to comment https://forums.phpfreaks.com/topic/114748-form-submission-fails-when-hitting-enter-instead-of-clicking-submit-button/#findComment-605594 Share on other sites More sharing options...
Rottingham Posted August 1, 2008 Author Share Posted August 1, 2008 It is the only button yes! <table width="550" border="0" cellspacing="2" cellpadding="0"> <form name="inventory_search" action="inventory.php" method="post" > <input type="hidden" name="page" value="search" /> <tr> <td class="stat_title" width="85">Look For: </td> <td class="stat_title" width="170"><input style="width:163px;" type="text" name="LOOK_FOR" id="LOOK_FOR" value="" class="form_inputText" /></td> <td colspan="2"></td> </tr> <tr> <td class="stat_title" width="85" valign="top">Look In: </td> <td class="stat_title" colspan="3"> <input type="radio" name="LOOK_IN" value="All" checked /> All<br /> <input type="radio" name="LOOK_IN" value="Part_Num" /> Part Number<br /> <input type="radio" name="LOOK_IN" value="Sales_Description" /> Description</td> </tr> <tr> <td><input type="submit" name="submit" value="Search" class="button_small" /></td></tr> </tr> </form> </table> Quote Link to comment https://forums.phpfreaks.com/topic/114748-form-submission-fails-when-hitting-enter-instead-of-clicking-submit-button/#findComment-605596 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.