Acute Chaos Posted June 27, 2011 Share Posted June 27, 2011 So I have various things I'm putting together with 'submit' buttons. Why... when I have the users log in they can either click the "log in" button or just hit enter on their keyboard and it works fine. But When they search in the directory the enter key doesn't work. You have to click the 'search' button. If you hit 'enter' on the keyboard, the field resets to blank and nothing happens. What am I missing here?? Is there a common issue I don't know about? thanks! Quote Link to comment https://forums.phpfreaks.com/topic/240534-enter-key-doesnt-work-but-submit-does/ Share on other sites More sharing options...
Pikachu2000 Posted June 27, 2011 Share Posted June 27, 2011 It probably has something to do with your code. Quote Link to comment https://forums.phpfreaks.com/topic/240534-enter-key-doesnt-work-but-submit-does/#findComment-1235494 Share on other sites More sharing options...
Acute Chaos Posted June 27, 2011 Author Share Posted June 27, 2011 Here's the code: <?php if(isset($_POST['submit'])){ if(isset($_GET['go'])){ if(preg_match("/^[ a-zA-Z]+/", $_POST['name'])){ $name=$_POST['name']; $db=mysql_connect ("server", "user", "pass") or die ('I cannot connect to the database because: ' . mysql_error()); $mydb=mysql_select_db("mydb"); $sql="SELECT * FROM user WHERE f_name LIKE '$name%' OR l_name LIKE '$name%'"; $result=mysql_query($sql); $numrows=mysql_num_rows($result); echo "<p><b>" .$numrows . " </b> results found for " . "<i>" ."<b>'" . $name . "':</b>". "</i>" . "</p><p> </p>"; while($row=mysql_fetch_array($result)){ $FirstName=$row['f_name']; $LastName=$row['l_name']; $Email=$row['email']; echo "<ul>\n"; echo "<li><strong>" . $FirstName . " " . $LastName . "</strong></li>\n"; echo "<li>" . "<a href=mailto:" . $Email . ">" . $Email . "</a></li>\n"; echo "</ul>"; } } else{ echo "<p><font color='red'>Please enter a search query</font></p>"; } } } If I hit 'enter' without anything in the field, it echos 'Please enter a search query' - - so I know it is recognizing the key being hit but if you hit 'enter' with text in the field it resets the page. Put in the same search term and click the 'search' button and you get the right result. hmmmm. Quote Link to comment https://forums.phpfreaks.com/topic/240534-enter-key-doesnt-work-but-submit-does/#findComment-1235502 Share on other sites More sharing options...
Pikachu2000 Posted June 27, 2011 Share Posted June 27, 2011 I don't see anything that jumps out as a problem. Can you post the form also, please? Quote Link to comment https://forums.phpfreaks.com/topic/240534-enter-key-doesnt-work-but-submit-does/#findComment-1235507 Share on other sites More sharing options...
Acute Chaos Posted June 27, 2011 Author Share Posted June 27, 2011 Sure - pretty simple form - all code is in the same page: <form method="post" action="search.php?go" id="searchform"> <input type="text" name="name"> <input type="submit" name="submit" value="Search"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/240534-enter-key-doesnt-work-but-submit-does/#findComment-1235509 Share on other sites More sharing options...
Pikachu2000 Posted June 27, 2011 Share Posted June 27, 2011 From what I can see, it should work, but try a couple things. First change the way you check to see if the form is submitted. There's a bug that isn't seen too often, but it can affect the way certain browsers handle sending the value of a submit button when the enter key is used. // FROM if(isset($_POST['submit'])) { // TO if(strtolower($_SERVER['REQUEST_METHOD']) === 'post' ) { If that doesn't make any difference, start echoing messages at different points in the code to see where it's stopping. if(strtolower($_SERVER['REQUEST_METHOD']) === 'post' ) { echo 'POST is set<br>'; // <--- ECHO if(isset($_GET['go'])) { echo 'GET go is set<br>'; // <--- ECHO if(preg_match("/^[ a-zA-Z]+/", $_POST['name'])) { echo 'POST[\'name\'] validates<br>'; // <--- ECHO $name=$_POST['name']; echo "$name<br>"; // <--- ECHO $db=mysql_connect ("server", "user", "pass") or die ('I cannot connect to the database because: ' . mysql_error()); See what happens, and post the results . . . Quote Link to comment https://forums.phpfreaks.com/topic/240534-enter-key-doesnt-work-but-submit-does/#findComment-1235517 Share on other sites More sharing options...
Acute Chaos Posted June 27, 2011 Author Share Posted June 27, 2011 k - tx I have to put it aside for a bit here and get some other work done but I'll let you know when I try this out. Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/240534-enter-key-doesnt-work-but-submit-does/#findComment-1235523 Share on other sites More sharing options...
Acute Chaos Posted June 27, 2011 Author Share Posted June 27, 2011 Actually .... I haven't been testing cross browser and I just tried a few different ones. So far it only seems to be a problem in IE8. Which still doesn't make a lot of sense considering the same browser works fine with other forms I have put together which are virtually the same. At least it doesn't make sense to me... Ok back to work!! Quote Link to comment https://forums.phpfreaks.com/topic/240534-enter-key-doesnt-work-but-submit-does/#findComment-1235527 Share on other sites More sharing options...
mikosiko Posted June 27, 2011 Share Posted June 27, 2011 here is an explanation and a couple solutions: http://social.msdn.microsoft.com/Forums/en-US/iewebdevelopment/thread/4908e026-088f-470a-9c57-d6bcde8882d0/ Quote Link to comment https://forums.phpfreaks.com/topic/240534-enter-key-doesnt-work-but-submit-does/#findComment-1235532 Share on other sites More sharing options...
Acute Chaos Posted June 27, 2011 Author Share Posted June 27, 2011 I'm not doing a good job at getting back to my other work! lol I tried that link mikosiko. Interesting for sure. Three suggestions there. Two don't work. One did - putting in the hidden field to trick IE but I haven't tested it thoroughly. I'll do that in a bit but for starters it seemed good. Thanks again. Still want to look into Pikachu's suggestions. tx folks. Quote Link to comment https://forums.phpfreaks.com/topic/240534-enter-key-doesnt-work-but-submit-does/#findComment-1235544 Share on other sites More sharing options...
Pikachu2000 Posted June 27, 2011 Share Posted June 27, 2011 It sounds like its going to end up being the single-field form issue that mikosiko posted. First time I've heard of that one. Quote Link to comment https://forums.phpfreaks.com/topic/240534-enter-key-doesnt-work-but-submit-does/#findComment-1235564 Share on other sites More sharing options...
Acute Chaos Posted June 27, 2011 Author Share Posted June 27, 2011 cool - thanks again Quote Link to comment https://forums.phpfreaks.com/topic/240534-enter-key-doesnt-work-but-submit-does/#findComment-1235592 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.