joePHP Posted May 5, 2008 Share Posted May 5, 2008 Hi, I have a form that it’s action is sent to the same page (the page with the form itself is on action="current_page.php"). Now I know I could use if(isset($_POST['submit'])) so the page refreshes and etc. but what could I do if I used an Image instead of a Submit on the form? Any suggestions? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/104255-solved-form-submit-using-image-and-not-submit/ Share on other sites More sharing options...
rhodesa Posted May 5, 2008 Share Posted May 5, 2008 first, if the form is posting to ifself, leave the action off of the form element. itself is the default action. and, i use this to catch all my posts: <?php if($_SERVER['REQUEST_METHOD'] == 'POST'){ //Form submitted } ?> Quote Link to comment https://forums.phpfreaks.com/topic/104255-solved-form-submit-using-image-and-not-submit/#findComment-533734 Share on other sites More sharing options...
joePHP Posted May 5, 2008 Author Share Posted May 5, 2008 Thanks Aaron, The only problem I realized is if the if has an else then the else will happen on load (I need check if this also happens with if(isset($_POST['submit']))) Quote Link to comment https://forums.phpfreaks.com/topic/104255-solved-form-submit-using-image-and-not-submit/#findComment-533788 Share on other sites More sharing options...
PFMaBiSmAd Posted May 5, 2008 Share Posted May 5, 2008 It is not clear what you are asking, but if you want to use an image as a submit button, read this - http://www.php.net/manual/en/faq.html.php#faq.html.form-image Quote Link to comment https://forums.phpfreaks.com/topic/104255-solved-form-submit-using-image-and-not-submit/#findComment-533854 Share on other sites More sharing options...
rhodesa Posted May 5, 2008 Share Posted May 5, 2008 No else...where is there an else? Quote Link to comment https://forums.phpfreaks.com/topic/104255-solved-form-submit-using-image-and-not-submit/#findComment-533897 Share on other sites More sharing options...
AndyB Posted May 5, 2008 Share Posted May 5, 2008 if(isset($_POST['submit'])) fails with an image submit with a compliant browser (IE as it happens) if(isset($_POST['submit_x'])) works with an image submit. Check the link that PFMaBiSmAd provided. Quote Link to comment https://forums.phpfreaks.com/topic/104255-solved-form-submit-using-image-and-not-submit/#findComment-533952 Share on other sites More sharing options...
rhodesa Posted May 5, 2008 Share Posted May 5, 2008 I still don't see the need. Here is a working example: <?php if($_SERVER['REQUEST_METHOD'] == 'POST'){ //Form submitted //do stuff print "You submitted: ".$_POST['my_text']; exit; } ?> <html> <body> <form method="POST"> <input type="text" name="my_text" /> <button type="submit" style="background:transparent;border:0;"><img src="http://media.msnbc.msn.com/i/msnbc/Components/Art/SITEWIDE/buttons/Submit.gif" /></button> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/104255-solved-form-submit-using-image-and-not-submit/#findComment-533970 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.