Solved

How can I submit a form by pressing enter and using an image as the submit type?

Posted on 2008-10-19
6
229 Views
Last Modified: 2013-11-19
I have form using an image as a submit button.

It won't submit when I press enter...only if I click the button.

This may not be a PHP help but I figured I throw it out here and see if anyone could point me in the right direction.

I've been all over Google and the only reference I could find was standard type='submit'.
if (isset($_POST['MainSearch_y'])){

execute code

}

Open in new window

0
Comment
Question by:phpretard
  • 3
  • 3
6 Comments
 
LVL 6

Expert Comment

by:trickyidiot
ID: 22753259
along with the image button that submits the form, have an actual submit button within a hidden div
<form method="post.....
 

<input type="button" src="CustomSubmitButton.gif" onClick="this.submit();">

<div style="display:none;">

  <input type="submit" name="submit" value="submit">
 

</form>

Open in new window

0
 

Author Comment

by:phpretard
ID: 22753418
This is what I have and it doesn't seem to work...
Any thoughts?
<form action='' method=post>

<input class='main_search' type='text' name='PrimSearch' autocomplete=off>

<div style='display:none;'><input type='submit' name='MainSearch_y' value='submit'></div>

<input type='image' border=0 src='http://www.fhaappraisershere.com/images/search.gif' name='MainSearch' onClick=\"this.submit();\">

</form>

Open in new window

0
 
LVL 6

Expert Comment

by:trickyidiot
ID: 22753454
you need to assign an action to the form. If you're posting to the same script that contains the form, you need to supply the name of the script.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:phpretard
ID: 22753488
I am submitting to an included file.  ie <? include ("submit"); ?>
This form is on every page.
Could explain a little more.  I am a little slow...
// The contents of submit.
 

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

$PrimSearch=$_POST['PrimSearch'];

$PrimSearch=strtoupper($PrimSearch);
 

	if (($PrimSearch=='ENTER A ST OR ZIP CODE')||($PrimSearch=='')){

	$search_message="<img src='images/exclaim.gif'> <b>You Must Enter Search Criteria</b>";

	$pass="NO";

	unset($_SESSION['search']);

	}

	

	if ((!ereg('[^0-9]', $PrimSearch)) && ((strlen($PrimSearch) < 5))){

	$search_message="<img src='images/exclaim.gif'> <b>A Zip Code Must Contain 5 Digits</b>";

	$pass="NO";

	unset($_SESSION['search']);

	}

	

			
 

if ($pass!="NO"){

$_SESSION['search']=$PrimSearch;

header("location: ?page=listing/results");

}
 
 

}

Open in new window

0
 
LVL 6

Accepted Solution

by:
trickyidiot earned 500 total points
ID: 22753526
Rather than checking for existance of the submit button's passed value, look for the user supplied entry into the search box

So:

Instead of this:
if (isset($_POST['MainSearch_y'])){

do this:
if (!empty($_POST['PrimSearch'])){
0
 

Author Closing Comment

by:phpretard
ID: 31507616
I wish I had more points to give!
Thank you!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem to be resolved in this article Currently, development of website and web application can be done without writing thousands of lines of programming code by hand. Description This can be done through by using a open source framework such …
"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now