Solved

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

Posted on 2008-10-19
6
232 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
How our DevOps Teams Maximize Uptime

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

 

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

"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,…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

726 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