tfburges Posted July 10, 2008 Share Posted July 10, 2008 I'm trying to use input images as multiple submit buttons. This is my code: <input type=image src=create.png name=create id=create border=0 value=submit> <input type=image name=remove id=remove src=remove.png border=0 value=submit> And in the page to which is posts: $rem = $_POST['remove']; $cre = $_POST['create']; Echoing $rem and $cre return nothing. Each SHOULD return 'submit,' according to other examples. There are no errors in my error log. I've looked for working examples of the same thing all over the net, as this is fairly common, and my code matches what I've found with the exception of different variable names. I must be overlooking something but I can't figure out what. Link to comment https://forums.phpfreaks.com/topic/114118-not-posting/ Share on other sites More sharing options...
lemmin Posted July 10, 2008 Share Posted July 10, 2008 The input type=image object doesn't have a value property. You probably want to make multiple forms with different input type=hidden objects for your values. Link to comment https://forums.phpfreaks.com/topic/114118-not-posting/#findComment-586540 Share on other sites More sharing options...
kenrbnsn Posted July 10, 2008 Share Posted July 10, 2008 When you use images for a submit button, MSIE doesn't return $_POST['name'], just $_POST['name_x'] and $_POST['name_y']. Firefox will return $_POST['name']. BTW, you should always quote all attribute values in your HTML tags: <input type="image" src="create.png" name="create" id="create" border=0 value="submit"> <input type="image" name="remove" id="remove" src="remove.png" border="0" value="submit"> Ken Link to comment https://forums.phpfreaks.com/topic/114118-not-posting/#findComment-586542 Share on other sites More sharing options...
tfburges Posted July 10, 2008 Author Share Posted July 10, 2008 Man, that's pretty lame; but I guess that's how the internet works. Not all sources are true. I read from multiple sources that "value" was a valid parameter. Upon more research, I found out that the parameter doesn't work in IE, but it does in Firefox. And upon even more research, I found out that the following code works perfectly: (Long story short, change $_POST['image_name'] to $_POST['image_name_x'] or $_POST['image_name_y'] since that's how PHP handles inputs of the type, image.) <input type=image name=remove id=remove src=remove.png border=0> <input type=image src=create.png name=create id=create border=0> $rem = $_POST['remove_x']; $cre = $_POST['create_x']; if($rem) { $idlist = join(',' , $_POST['del']); mysql_query("DELETE FROM `formz` WHERE `id` IN ($idlist)"); } else if ($cre) { $qc1 = "SELECT `field_desc_i` FROM `formz` WHERE `formx_name_v` = '$formx_name_v'"; etc... Source: http://articles.techrepublic.com.com/5100-10878_11-5242116.html Using graphical submit buttons A minor twist in the tale comes if you use a graphical submit button, as in the following simple form: <html><head>Graphical submit button</head> <body> <form action="processor.php" method="post"> Search for: <input type="text" name="q"> <input type="image" name="go" src="/images/go.gif"> </form> </body> </html> When this form is sent to PHP for processing, look what the $_POST array contains: Array ( [q] => magpie [go_x] => 13 [go_y] => 13 ) Because it's a graphical button, PHP actually tracks the mouse coordinates of the mouse click and creates two elements in the result array to store those coordinates. The elements are named [button_name]_x and [button_name]_y respectively. Why is this important? Well if you'd been using an if() test keyed on the submit control's "name" the test would have failed because instead of creating a single element accessible through $_POST['go'], PHP actually created two elements named $_POST['go_x'] and $_POST['go_y'] respectively. Make a mental note of this for future reference; it might save you some time when things don't work as expected. So now, what happens if you have multiple graphical submit buttons in your form: <html><head>Multiple graphical submit buttons</head> <body> <form action="processor.php" method="post"> Enter part number: <input type="text" name="part"> <br> <input type="image" name="view" src="/images/view.gif"> <input type="image" name="edit" src="/images/edit.gif"> <input type="image" name="delete" src="/images/delete.gif"> <input type="image" name="order" src="/images/order.gif"> </form> </body> </html> Your PHP script would need to contain multiple branches, something like this: <?php if ($_POST['view_x']) { // code to view record } else if ($_POST['edit_x']) { // code to edit record } else if ($_POST['delete_x']) { // code to delete record } else if ($_POST['order_x']) { // code to place an order } ?> Link to comment https://forums.phpfreaks.com/topic/114118-not-posting/#findComment-586623 Share on other sites More sharing options...
PFMaBiSmAd Posted July 10, 2008 Share Posted July 10, 2008 This is actually one case where IE is following the rules and the other browsers are not. $_POST['image_name_x'] or $_POST['image_name_y'] works in all current browsers. Link to comment https://forums.phpfreaks.com/topic/114118-not-posting/#findComment-586781 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.