SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2010
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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:
    HTML Code:
    <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:
    PHP Code:
    //Appears before HTML tag

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

         
    $search $_POST['searchInput'];

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


    HTML Code:
    <!-- 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.

  2. #2
    SitePoint Enthusiast webdesignhouston's Avatar
    Join Date
    Dec 2010
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is a known behavior of IE. Try replacing the submit button with a hidden field such as:

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

  3. #3
    SitePoint Enthusiast
    Join Date
    Sep 2010
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by webdesignhouston View Post
    This is a known bug in IE. Try replacing it with a hidden field such as:

    Code HTML4Strict:
    <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).

  4. #4
    SitePoint Enthusiast
    Join Date
    Sep 2010
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just gave it a shot and everything now seems to be working.

    Thanks again!!

    PS: I do not like IE...

  5. #5
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    or you could just change your isset to look at $_POST['searchInput'] instead....


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •