Solved

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

Posted on 2008-10-19
6
233 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
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 

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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
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:
The viewer will learn how to count occurrences of each item in an array.

718 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