Alicia Posted September 28, 2012 Share Posted September 28, 2012 Hi, I am trying to create a simple form with image buttons but why my php page can't capture the value of the image button clicked? can somebody give me a hint about this.. thankyou <form id="form1" name="form1" method="post" action="process.php"> <tr> <td colspan="2"><input type="image" name="Submit" id="Submit" src="images/01.jpg" value="Mobile" /></td> <td> <input type="image" name="Submit" src="images/03.png" id="Submit" value="Hardware" /></td> <td> </td> <td> </td> </tr> </form> in my php file i put use this code.. it is very simple and straight forward but wonderng why nothing is printed.. Other elements in the form can be printed except the value of the submit image. =( echo $_POST['Submit']; Quote Link to comment https://forums.phpfreaks.com/topic/268877-why-my-form-is-not-working/ Share on other sites More sharing options...
floridaflatlander Posted September 28, 2012 Share Posted September 28, 2012 (edited) Try <form id="form1" name="form1" method="post" action="process.php" enctype="multipart/form-data" > added sorry I think I got what you want wrong. Are you trying to upload an image? Edited September 28, 2012 by floridaflatlander Quote Link to comment https://forums.phpfreaks.com/topic/268877-why-my-form-is-not-working/#findComment-1381511 Share on other sites More sharing options...
Barand Posted September 28, 2012 Share Posted September 28, 2012 (edited) Clicking on images sends x,y coordinates. Try this code so you can see what is in the POST array echo '<pre>'.print_r($_POST, 1).'</pre>'; Edited September 28, 2012 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/268877-why-my-form-is-not-working/#findComment-1381512 Share on other sites More sharing options...
jazzman1 Posted September 28, 2012 Share Posted September 28, 2012 <input type="image" name="Submit" src="images/03.png" id="Submit" value="Hardware" /> Not Equal To <input type="submit" name="Submit" id="Submit" value="Hardware" /> If you want to check whether the form has been submitted, you could use a hidden input field. Quote Link to comment https://forums.phpfreaks.com/topic/268877-why-my-form-is-not-working/#findComment-1381548 Share on other sites More sharing options...
Alicia Posted September 28, 2012 Author Share Posted September 28, 2012 i am not uploading any image so the form type is not what i need.. actually i have 2 image buttons for them to click..in my php file, i want to do conditional statement $_POST['Submit'] == a do this or b do that so hidden value wont work in this case since we need to perform an action based on the image button clicked\ any guru can advise Quote Link to comment https://forums.phpfreaks.com/topic/268877-why-my-form-is-not-working/#findComment-1381568 Share on other sites More sharing options...
ManiacDan Posted September 28, 2012 Share Posted September 28, 2012 Someone asked you to print_r post. Quote Link to comment https://forums.phpfreaks.com/topic/268877-why-my-form-is-not-working/#findComment-1381572 Share on other sites More sharing options...
PFMaBiSmAd Posted September 28, 2012 Share Posted September 28, 2012 The value attribute of an image being used as a submit button won't be submitted (well it will by some browsers, but those are not following the w3.org specification.) To distinguish which image was clicked, that will work in all browsers, you must use different names for each one. Quote Link to comment https://forums.phpfreaks.com/topic/268877-why-my-form-is-not-working/#findComment-1381573 Share on other sites More sharing options...
Alicia Posted September 28, 2012 Author Share Posted September 28, 2012 print_r($_POST, 1) shows nothing... no.. different name doesn't work either.. it still print nothing.. any guru can assist.. this looks simple but why not able to solve the issue =( Quote Link to comment https://forums.phpfreaks.com/topic/268877-why-my-form-is-not-working/#findComment-1381591 Share on other sites More sharing options...
ManiacDan Posted September 28, 2012 Share Posted September 28, 2012 print_r($_POST, 1) would show nothing...unless you put it inside the rest of the statement like you were asked to do. Why not able to solve the issue is because you're not giving us any information. Copy and paste the command you were given. Show the output. It absolutely 100% will always print something. Show us that something. Quote Link to comment https://forums.phpfreaks.com/topic/268877-why-my-form-is-not-working/#findComment-1381602 Share on other sites More sharing options...
Alicia Posted September 28, 2012 Author Share Posted September 28, 2012 I managed to solve this one by using css button.. another new question if any guru can assist. now I put this <input type="hidden" name="checkboxes[]" value="<? echo $row['memo'] ?>" /><input type="hidden" name="checkboxes[]" value="<? echo $row['memo'] ?>" /> inisde a for loop when I posted to the php file, it has error : Warning: Invalid argument supplied for foreach() in when I use this : foreach($_POST['checkbox'] as $copid){ The code works when I use it as checkbox but why it doesn't work anymore after I changed it to hidden value ? any idea?? Quote Link to comment https://forums.phpfreaks.com/topic/268877-why-my-form-is-not-working/#findComment-1381605 Share on other sites More sharing options...
darkfreaks Posted September 28, 2012 Share Posted September 28, 2012 This will not work as stated sending images outputs X and Y cordinates if(isset($_POST['submit'])) { //** Do Stuff **// } however this will because it includes the X & Y cordinates in the submit. if(isset($_POST['submit_x') && isset($_POST['submit_y'])) { //**DO Stuff**// } Quote Link to comment https://forums.phpfreaks.com/topic/268877-why-my-form-is-not-working/#findComment-1381607 Share on other sites More sharing options...
ManiacDan Posted September 28, 2012 Share Posted September 28, 2012 Checkboxes need to be checked in order to pass information. You shouldn't use checkboxes for this anyway though, the session is more correct for passing data between page loads. Quote Link to comment https://forums.phpfreaks.com/topic/268877-why-my-form-is-not-working/#findComment-1381608 Share on other sites More sharing options...
Christian F. Posted September 28, 2012 Share Posted September 28, 2012 (edited) Also, "checkboxes" != "checkbox". Edited September 28, 2012 by Christian F. Quote Link to comment https://forums.phpfreaks.com/topic/268877-why-my-form-is-not-working/#findComment-1381609 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.