Jump to content

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


Rottingham

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>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.