Solved

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

Posted on 2008-10-19
6
226 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:phpretard
Comment Utility
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
Comment Utility
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
Comment Utility
I wish I had more points to give!
Thank you!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn how to count occurrences of each item in an array.

772 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now