?
Solved

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

Posted on 2008-10-19
6
Medium Priority
?
234 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
A new era in Cloud training has arrived.

A day that will go down in Cloud history.. But are you ready for it? Will you accept this Cloud challenge?

 

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 2000 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
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 is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses

801 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