Solved

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

Posted on 2008-10-19
6
230 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
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:
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

803 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