/    Sign up×
Community /Pin to ProfileBookmark

IE7 Enter key submits form but doesn’t process it

Hi,

Bizarre problem with a very basic php search form/script that only seems to show up in IE7.

If I fill in the search box and press the Enter key on the keyboard, the form appears to submit (the search box is cleared as if the page is refreshed, which is what should happen since this same page is also supposed to process the form). However, the query is never processed by the PHP script on the page. If I click the submit button, everything is fine.

Below is my form HTML and the PHP.

[code=php]
<div class=”searchBox”>
<form id=”databasesearch” name=”databasesearch” method=”post” action=””>
<input name=”searchquery” type=”text” id=”searchquery” size=”30″ value=””/>
<input type=”submit” name=”search” id=”search” value=”Find” />
</form>
</div>
<div class=”resultsarea”>
<ul>
<?php
require (‘../mysql_connect.inc’);
if (isset($_POST[‘search’])) {
$query = “select metalib_id, title_display from xerxes_databases where title_display LIKE ‘%{$_POST[‘searchquery’]}%’ order by title_display”;
$result = mysql_query($query);
if (mysql_num_rows($result) > 0) {
while ($database = mysql_fetch_array ($result, MYSQL_ASSOC)) {
echo “<li><a href=”http://aleph19.pacific.edu/_metasearch/databases/proxy/$database[metalib_id]”>$database[title_display]</a></li>”;
}
} else {
echo “<div align=”center” style=”color: #cc0000; font-weight: bold”>Sorry. There were no results for <span style=”color: black”>&quot;{$_POST[‘searchquery’]}&quot;</span>.</div>”;
}
}
?>
</ul>
</div>
[/code]

Any ideas as to why IE7 won’t process the PHP if you press the Enter key?

Thanks,
Glenn

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@sstalderAug 13.2008 — [code=php]
<form id="databasesearch" name="databasesearch" method="post" action="<?PHP echo $_SERVER['PHP_SELF']; ?>">
[/code]

If you properly code your form tags it should work, give that a try above.

If not please provide more detail, for example if you press the form button, it works? It works in other browsers?
Copy linkTweet thisAlerts:
@pillsburauthorAug 13.2008 — Hi,

Thanks for the reply. I already had that php in the action element before and removed it during my initial testing of the problem. Whether it's there or not has no effect: the php is not being processed in IE7 though it appears the form is being submitted *somewhere*.

Also, maybe I wasn't clear before: the problem only occurs if you press the Enter key in IE7. If you click the "Find" submit button in any browser including IE7 (I also tested FF, Opera, and Safari), the form submits and the php works.

Thanks again,

Glenn
Copy linkTweet thisAlerts:
@maverukAug 14.2008 — Are there more than one forms on the page? If so, then it could submit to the wrong form.
Copy linkTweet thisAlerts:
@sstalderAug 14.2008 — What if you change your PHP to:

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

I have no idea though, unless you have other code affecting this somewhere.
Copy linkTweet thisAlerts:
@ian_dJan 07.2009 — Hi,

Sorry to bring this thread right back from the dead, but I have exactly the same problem that is really, really bugging me.

Was a solution/fix ever found for this?

Thanks in advance.
Copy linkTweet thisAlerts:
@ian_dJan 07.2009 — For those that may come accross this problem in the future, I have found a solution.

It does seem to be a bug in IE7, I found it also occured in IE6 (although not tested any others).

The problem arose because I was only using 1 input field before entering. For some reason this affects whatever when you press enter.

I also tried adding a hidden field but the outcome was the same. In the end, this solved it:

[code=html]<input type="text" style="height:0;width:0;border:0;margin:0;padding:0;" name="field-so-enter-works-in-ie" />[/code]

Hope this helps someone one day ?
Copy linkTweet thisAlerts:
@NogDogJan 07.2009 — The hidden field should work, just make sure you rename or remove the "name" attribute in the submit button element so that it is not the same as that of the hidden field, in which case it would override the hidden field's name.
×

Success!

Help @pillsbur spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...