...

View Full Version : Problems with using an image for a submit button in a form



reub77
10-09-2002, 05:15 AM
I would like to use an image instead of an ugly submit button. Here is my code:

<!--This doesn't work-->

<form name='form$x' method='post' action='projLeads.php'> <input type='hidden' name='ID' value='$jobID'>
<input type='image' src='images/remove.gif' alt='Delete' name='Delete' width='13' height='15'>
</form>

<!--This does-->

<form name='form$x' method='post' action='projLeads.php'> <input type='hidden' name='ID' value='$jobID'>
<input type='submit' name='Delete' value='Delete'>
</form>

This is the code that processes the form:

<?PHP
if($Delete) {
$conn = db_connect();
//declare query
$query = 'DELETE FROM currProjects WHERE id="'.$ID.'"';
//execute query
$result = mysql_query($query);
//declare query
$query = 'DELETE FROM invoices WHERE id="'.$ID.'"';
//execute query
$result = mysql_query($query);
//declare query
$query = 'DELETE FROM contracts WHERE id="'.$ID.'"';
//execute query
$result = mysql_query($query);
}
?>

So the first bunch of coding is what I want to get to work. The second works. The third is just to give you a better idea as to what I'm trying to do, it works.

How can I use the image submit button to work properly as a submit button?

JustAsking
10-09-2002, 05:21 AM
<!--This doesn't work-->

<form name='form$x' method='post' action='projLeads.php'> <input type='hidden' name='ID' value='$jobID'>
<input type='image' src='images/remove.gif' alt='Delete' name='Delete' width='13' height='15'>
</form>

THIS SHOULD WORK!!

<form name="form$x" method="post" action="projLeads.php"> <input type='hidden' name='ID' value='$jobID'>
<input type="image" action="submit" src="images/remove.gif" alt="Delete" name="Delete" width="13" height="15">
</form>

reub77
10-09-2002, 05:28 AM
I did exactly as you indicated. I added the action="submit". The database row did not delete. When switching it with the ugly button it worked. I'm still lost as to what to do. You may be onto something though, keep thinking.

dauvm
10-09-2002, 05:54 AM
That is very wierd... I just did a lot of searching and this is the correct syntax for using an image as a submit button

<input type="image" src="submit.gif" height="20" width="60" border="0" alt="Submit your info">

whiiich is exactly what you have. hhmm..
i wonder if your php script would take the "Delete" from another <input type="hidden" name="Delete" value="Delete"> like that? then just use the submit button...
or maybe try adding the value in like it is in the ugly button form <input type="image" name="delete" value="delete">
just throwing out ideas!

adios
10-09-2002, 07:12 AM
An <input type="image"> submit is a sort of $0.98 image map: it submits its own data to the server as:

Delete.x=73&Delete.y=14

...where x & y are the left & top co-ordinates of the click point on the image. This is presumably to allow for a variety of submit possibilities, based on where the user clicked; in practice, it alters the format of the posted data. If you don't care to parse this out at the server, try:

<form name="f1" onsubmit="return true;">
<input type="hidden" name="Delete" value="Delete">
<a href="javascript:if(document.f1.onsubmit())document.f1.submit()">
<img border="0" src="images/remove.gif" alt="Delete" width="13" height="15"></a>
</form>

The Form.submit() method doesn't call the Form.onsubmit handler so the above does it explicitly; if you're not using an onsubmit validator, e.g., be sure and use the return true statement, or simply eliminate this completely:

if(document.f1.onsubmit())

cya, adios



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum