Forum Moderators: coopster

Message Too Old, No Replies

submit with image button

submit image button form help arrey

         

Gruessle

5:46 am on Feb 27, 2005 (gmt 0)

10+ Year Member



This works fine:
<form name='form1' method='post' action=$PHP_SELF>
<input name='delid' type='hidden' value=$qry[id]>
<input type='submit' name='delete' value=Delete>
</form>

How do I get this to work:
<form name='form1' method='post' action='$PHP_SELF'>
<input name='delid' type='hidden' value='$qry[id]'>
<input name'delete' action='submit' type='image' src='/images/delete.png' alt='Delete' width='20' height='20' border='0'>
</form>

I been playing and thougt this should work but it doesn't:

} else if ($delete) {
$array = split(" ",$delid,3);
$delid = CheckAndTrim($array[0]);
echo "$delid <br>"; // this shows the right number
$sql = "DELETE FROM profile_edu WHERE id=$delid";
$result = mysql_query($sql);
echo "$sql - Row deleted!<br>";
}

I been reading and reading about how to do this.

I found something which solves the problem with javascript. Which is not acceptable to me.

[edited by: jatar_k at 5:42 pm (utc) on Feb. 27, 2005]
[edit reason] removed url [/edit]

dreamcatcher

9:09 am on Feb 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Firstly, when using form data you should always use the PHP superglobals. ie: $_POST, $_GET etc. Register globals are off by default in PHP and even though your server may have them on, its best to be safe and use the superglobals for security.

When using images it maps x and y co-ordinates. There is a thread on this already somewhere, but I can`t find it.

So, try this:


else if(isset($_POST['delete']) ¦¦ isset($_POST['delete_x']))
{
$array = split(" ",$delid,3);
$delid = CheckAndTrim($array[0]);
echo "$delid <br>"; // this shows the right number
$sql = "DELETE FROM profile_edu WHERE id=$delid";
$result = mysql_query($sql);
echo "$sql - Row deleted!<br>";
}

dc

dmmh

9:59 am on Feb 27, 2005 (gmt 0)

10+ Year Member



<form name="form1" method="post" action="echo $PHP_SELF">
<input name="delid" type="hidden" value="<? echo $qry[id];?>">
<input type="image" src="/images/delete.png" onClick="this.form.submit()">

dmmh

11:36 am on Feb 27, 2005 (gmt 0)

10+ Year Member



mmm, missed the part you cant use javascript

dmmh

11:40 am on Feb 27, 2005 (gmt 0)

10+ Year Member



action isnt a valid atribute for input type image by the way, so even if you get it to work, it is doubtable that it will work crossbrowser

[w3.org...]

Gruessle

7:31 pm on Feb 27, 2005 (gmt 0)

10+ Year Member




Hi dreamcatcher,
Thank you for your advise, you are right about the global off thing. I will fix all my pages.

Your version gives me blank screen
so I played with it.

Following works without images that after does not work with or without image form.

}
else if (isset($_POST['delete']))
{
$sql = "DELETE FROM profile_bio WHERE id=$delid";
$result = mysql_query($sql);
echo "Row deleted!<p>";
}

======Following does not work==========

}
else if ((isset($_POST['delete'])) ¦¦ (isset($_POST['delete_x'])))
{
$sql = "DELETE FROM profile_bio WHERE id=$delid";
$result = mysql_query($sql);
echo "Row deleted!<p>";
}

dreamcatcher

9:47 pm on Feb 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just one quick thing I noticed. In your original post you have:

<input name'delete'

Should be:

<input name='delete'

dc