Link to home
Start Free TrialLog in
Avatar of phpretard
phpretard

asked on

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

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

Avatar of trickyidiot
trickyidiot

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

Avatar of phpretard

ASKER

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

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

ASKER CERTIFIED SOLUTION
Avatar of trickyidiot
trickyidiot

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I wish I had more points to give!
Thank you!