We help IT Professionals succeed at work.

PHP Search only works when clicking "submit"When you press the "Enter" key it runs the reset button

TitoCebolla
TitoCebolla asked
on
609 Views
Last Modified: 2012-05-11
PHP Search only works when clicking "submit" When you press the "Enter" key it runs the reset button and not the submit button. I really need for it to submit when enter key is pressed.

Thanks,


www.ccttero.com is the website and here is the contents of the code for the search window.

<tr align="center">

                  <td><font size="-1" color="#002b40" face="Arial, Helvetica, sans-serif"><strong>Search </strong></font>

                  <input type="text" name="searchTerm" value="<?php echo $searchTerm; ?>" size="50"/>

                  <input type="submit" name="submit" value="Submit" hidefocus="true" onKeyPress="return processKey(this,event)" />

                  <input type="submit" name="reset" value="Reset" />                  </td>

      </tr>
Comment
Watch Question

Lead Developer
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Most Valuable Expert 2011
Author of the Year 2014

Commented:
Throw away the RESET button entirely.  You never see that on a search form any more!
Most Valuable Expert 2011
Author of the Year 2014

Commented:
One other thing to look out for.  Your code looks like it might depend on "register_globals" and you probably want to get past that issue as soon as possible.
http://php.net/manual/en/security.globals.php

Best regards, ~Ray

Author

Commented:
If I delete the reset button will it use the "submit" button when you press the enter Key? Thats what I need but also I would like to keep the reset button if possible.

Thanks,
Greg AlexanderLead Developer

Commented:
Did you try my solution?

Author

Commented:
I aplogize "g" but I did not understand your submission but if I can I am definitaly willing to try.

thanks,
Greg AlexanderLead Developer

Commented:
 <input type="reset" name="reset" value="Reset" />        

instead of

  <input type="submit" name="reset" value="Reset" />        
Most Valuable Expert 2011
Author of the Year 2014

Commented:
If I delete the reset button will it use the "submit" button when you press the enter Key? - Yes, unless you have JavaScript that intervenes.
Thats what I need but also I would like to keep the reset button if possible. - Then keep the reset button, but before you decide you need a reset button, have a look at the search boxes on a handful of the popular web sites like Google, Yahoo, Facebook, etc.  No reset buttons.  Maybe there is a reason why they do that, and in my opinion they do that because the reset button has never made any sense at all.  It's an unnecessary part.

Author

Commented:
Didn't work Ray. Thanks tho....

Author

Commented:
No go "g" thanks tho.
      <tr align="center">

                  <td><font size="-1" color="#002b40" face="Arial, Helvetica, sans-serif"><strong>Search </strong></font>

                  <input type="text" name="searchTerm" value="<?php echo $searchTerm; ?>" size="50"/>

                  <input type="submit" name="submit" value="Submit" hidefocus="true" onKeyPress="return processKey(this,event)" />

                  <input type="reset" name="reset" value="Reset" />                  </td>

      </tr>
Most Valuable Expert 2011
Author of the Year 2014

Commented:
What does "didn't work" mean?  Parse error?  Message?  Halt and catch fire?

Please install this script and see if it works.  If not, tell us a little more about your browser and testing methods:
http://www.laprbass.com/RAY_form_thankyou_page.php
<?php // RAY_form_thankyou_page.php
error_reporting(E_ALL);
echo "<pre>\n";

// SHOW HOW TO DO FORM INPUT, VALIDATION, AND THANK YOU PAGE

// IF THERE IS SOMETHING THAT HAS BEEN POSTED
if (!empty($_POST))
{

    // THIS IS THE VALIDATION PROCESS - ONLY TWO RESULTS
    // EITHER A FAILURE PAGE OR A THANK YOU PAGE
    // CHECK TO SEE IF IT IS WHAT WE EXPECT
    if ($_POST["xyz"] != 'XYZ')
    {
        // CREATE ERROR PAGE IF DATA FAILED VALIDATION
        echo "\nSORRY YOU DID NOT ENTER XYZ";
    }
    else
    {
        // CREATE THANK YOU PAGE IF DATA PASSED VALIDATION
        echo "\nTHANK YOU, ";
        die("ALL DONE NOW");
    }

}// END OF PHP - PUT UP THE FORM
?>
<form method="post">
ENTER 'XYZ' IN UPPER CASE LETTERS HERE:
<input name="xyz" />
<input type="submit" />
</form>

Open in new window

Most Valuable Expert 2011
Author of the Year 2014

Commented:
Maybe you have omitted the <form> and </form> tags?

Author

Commented:
Didn't work means I deleted the reset button like you suggested, tested it by entering a search term and it still reset the page instead of submitting it.
Greg AlexanderLead Developer

Commented:
Whats the entire form look like?
Most Valuable Expert 2011
Author of the Year 2014

Commented:
Yes, let's see if there are <form> and </form> tags.  Those are not present in what you posted here.  Also you might try leaving out the JavaScript onKeyPress event for now.  Let's just get the form working first, then deal with the add-ons.

Author

Commented:
I do not see the <form> tag but I do see the </form> at almost the very end of all of the code.
I aplogize but I am just learning some of this. Here is the whole table code.


<table border="0" width="100%">

            <tr align="center">
            
             <p align="center"><font color="#000000" size="3">The order of preference shall be given in all RFP’s, IFB’s, and other contract solicitations in the following order: (1)100% Colville Business Enterprise (2)Colville Family Business Enterprise (3)Colville Business Enterprise (4)Indian Business Enterprise</font></p><br />
              <p align="center"><strong><font size="4" face="Times New Roman, Times, serif">Colville Confederated Tribes</font></strong></p><strong></em></font></strong><br />
          <font size="6"><p align="center">T</font><font size="4">ribal</font> <font size="6">E</font><font size="4">mployment</font>          <font size="6">R</font><font size="4">ights</font> <font size="6">O</font><font size="4">ffice</p></font> <font colo"#CC3333"           size="4" face="Times New Roman, Times, serif"><em><br />
          </em>
          <p align="center"><em><font color="#CC0000"><strong>Vendor Database Search</strong></font></em></p>
    </font></strong></font></h1></font><br /><p align="center"><font color="#000000" size="3">SEARCH TERM EXAMPLES:</font><font color="#8E7F73" size="3"> <font color="#000000" face="Times New Roman, Times, serif">Fencing, Paving, Wood Cutter, Carpentry, Demolition, Plumbing, Technology, Equipment Rental, Logging, Dump Truck ect.</font></font></p></em></font></strong></font></h1></font></tr>

            <tr align="center">

                  <td><font size="-1" color="#002b40" face="Arial, Helvetica, sans-serif"><strong>Search </strong></font>

                  <input type="text" name="searchTerm" value="<?php echo $searchTerm; ?>" size="50"/>

                  <input type="submit" name="submit" value="Submit" hidefocus="true" onKeyPress="return processKey(this,event)" />

                  <input type="reset" name="reset" value="Reset" />                  </td>

      </tr>

      </table>
Most Valuable Expert 2011
Author of the Year 2014

Commented:
I object to deleting this question.  You got many good replies, but you posted only partial pieces of code.  This left us with nothing to go on, and we may have wasted our time (and yours) because you gave us an incomplete picture of what was really happening.  And the notion that you "do not want my code out there" is not really much of an issue - we have all see millions of lines of bad code, so there is nothing important or special about the code that you are having issues with.

Candor, clarity and forthright discussion will be of value to you in your work with EE.  All the best, ~Ray
Most Valuable Expert 2011
Author of the Year 2014

Commented:
Please tell us how you solved it or tell us how our answers were unresponsive to your question.  We want to do the best we can.  Thanks, ~Ray
Most Valuable Expert 2011
Author of the Year 2014

Commented:
Thanks for sharing!  Good luck in your work, now and in the future, ~Ray
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.