Form value issues (IE): Enter vs: mouse click

the following issue is in IE 7 & 8. Chrome, Firefox, and IE 9 have no trouble

I’ve been scouring the web for a solution to this problem and have found several instances where people have had issues. Unfortunately I’ve yet to find an adequate response.

I have a search form who’s input values are being posted to search.php.

home.php:

<form name="searchForm" id="searchForm" method="post" action="search.php">
     <input type="text" name="searchInput" id="searchInput" value="" />
     <input type="submit" name="searchBtn" id="searchBtn" value="Search" />
</form>

Search.php:


//Appears before HTML tag

if(isset($_POST['searchBtn'])){

     $search = $_POST['searchInput'];

     if(isset($search)){
          $feedback = "Search query: " . $search;
     }else{
          $feedback = "Search is not set.";
     }

}
<!-- Appears in document body -->
<div id="searchResult"><?php echo $feedback; ?></div>

SO, the problem is that when the user enter a search term and physicall clicks the search button with the mouse, everything works out perfectly.

HOWEVER, when the user enters a search term and just presses enter on the keyboard, the value doesn’t pass to search.php and $search does not get set.

This is a known behavior of IE. Try replacing the submit button with a hidden field such as:


<input type="hidden" name="searchBtn" value="1"/>
<input type="submit" value="Search" /><!-- no name and/or id is required -->

And from here the PHP would remain the same? As in, I’m still checking if the searchBtn ‘isset’?

EDIT: I suppose I would as the value of the hidden input is 1 and would be set upon submission of the form…

Thanks so much for your help!!! I’ll give it a try and let you know if it’s still broken (in which case I’m sure user error will be the next thing to look at).

Just gave it a shot and everything now seems to be working.

Thanks again!!

PS: I do not like IE…

or you could just change your isset to look at $_POST[‘searchInput’] instead…