Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTML form with image for submit button

Status
Not open for further replies.

robburne

Programmer
May 10, 2005
33
GB
Hi,

I am using a standard html form but I want to use a graphic in place of the default submit button at the bottom of the form.

I am using this code:

<input type="image" src="button.jpg" name="submit">

When I submit my form a script catches the condition with as follows.........

if (isset($_POST['submit'])) {
DO SOMETHING
}

But using the image in place of the default button results in the if statement not evaluating as true.

If I swap thigs around so as to use the default:

<input type="submit" value"Go" name="submit">

The if statement behaves correctly. It is almost as if the theimage is causing the "name" variable of the form not to be passed.

Any ideas, thnaks!

Rob.
 
PHP read the value attribute of form elements, and you don't have any value assigned to the image input. Use something like this:

<input type="image" src="button.jpg" name="submit" value="dummyvalue">

Lee
 
The isset() function call means "Is there a value assigned to the indicated form element?". Since the element has no value, the function call will return false and none of the code in the conditional statement will be processed. If it worked fine with a regular submit button, the isset() function was reading the value, which is the text that the button displays. It actually did nothing, since if there was a submit button, it evaluated to true. If there wasn't a submit button, the form most likely wouldn't be submitted. I'd remove the

Code:
if (isset($_POST['submit']))

since it's not performing any logical function.

Lee
 
Thanks for the feedback.........

The if statement is necessary, the script itself is a set of tracking functions. If the form has not been submitted an input screen is displayed into which the user inputs consiggnment details. Else tracking info for a consignment is displayed.

In my case the user has input a tracking no. and then submitted the form. The if condition should evaluate as true.

As I said, it all works correctly with the standard submit button, logicallyit functions as I want and as it should. The image is causing a problem though.

Rob.
 
The if statement:

if (isset($_POST['submit']))

is defintely looking at the:

name="submit"

Because if I change the value to submit1 it does not catch it, but submit does.

Rob.
 
So what would be the correct syntaxt to check the x and y values of the image then?

Thanks,

Rob.
 
Forget about the isset for now and just do this:

Code:
<html><body>
<form method="get" action="#">
<input type="image" src="image.jpg" width="100px"; height="100px" />
</form>
</body></html>

Looking in the address window you will see that the x and y get passed in the query string. There is no need for a name for the image.

Clive
 
It gives me in the address bar....

test.htm?x=84&y=55

So in my script I tried:

if (isset($_POST['x']))

But it is not catching it still.

Puzzled!

Rob.

 
Ok I have managed to test the x and y variables and get my if statement to correctly parse the condition so all good there.

Now to the next problem (currently this has taken around 4 hours to implement an image submit button - unreal!).

The action part of theform looks like this.....

action="test.htm?job_num=job_num">

On the send to script I am testing the output as follows:

echo"$_POST[x] ; $_POST[y] ; $_POST[job_num]";

When I test the output using the default submit button there is obviously no putput for the x and y variables and the job_num variable outputs as "ARRAY" which is correct and as I want it.

However when I test the output with the image as a submit button I get:

Worldwide Courier - Gatwick

MENU

Services

Shipping Advice

Online Booking

Get A Quote

Open Account

Job Calculator

Currency Conversion

Contact & Location

x=67
y=14
job_num=77001538

Although the job_num value is correct why is it not in a variable, and can I make sureit is in a variable?

Thanks,

Rob.


 
Please disregard the following lines form my lastpost, I did not mean to paste them and can't see a way to edit my post.

Worldwide Courier - Gatwick
MENU
Services
Shipping Advice
Online Booking
Get A Quote
Open Account
Job Calculator
Currency Conversion
Contact & Location

 
I am sorry, want I want to ask is why is it not in an array and how can make it so?

Sorry very tired.

Rob.
 
Thanks for your help guys I finally solved it, I learnt something today! Don't mess with the default form button, lol!

Thanks,

Rob.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top