Jump to content

Form submission fails when hitting ENTER instead of clicking submit button...


Recommended Posts

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.

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).

  • 3 weeks later...

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){
}

 

 

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>

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.