kts Posted January 5, 2009 Share Posted January 5, 2009 I have used many different ways, what is the safest best way to do it for all server types. I've done if(isset($_POST['submit'])) doesn't always work, and checked for a hidden fields value to be 1, etc... I'm curious thanks. Quote Link to comment https://forums.phpfreaks.com/topic/139573-best-way-to-check-for-form-submit/ Share on other sites More sharing options...
flyhoney Posted January 5, 2009 Share Posted January 5, 2009 How would this not always work? if(isset($_POST['submit'])) Quote Link to comment https://forums.phpfreaks.com/topic/139573-best-way-to-check-for-form-submit/#findComment-730140 Share on other sites More sharing options...
castis Posted January 5, 2009 Share Posted January 5, 2009 make sure that the submit button in your form is as such. <button type="submit" name="submit" value="1">Click Here</button> $_POST['submit'] reads off the name attribute, and will contain "1". As long as your submit button has a name and a value, isset($_POST['submit']); will always work. Quote Link to comment https://forums.phpfreaks.com/topic/139573-best-way-to-check-for-form-submit/#findComment-730141 Share on other sites More sharing options...
revraz Posted January 5, 2009 Share Posted January 5, 2009 The only way that wouldn't work is if your Submit name wasn't "submit". Quote Link to comment https://forums.phpfreaks.com/topic/139573-best-way-to-check-for-form-submit/#findComment-730142 Share on other sites More sharing options...
kts Posted January 5, 2009 Author Share Posted January 5, 2009 I have a form right now.... if(isset($_POST['submit'])){ do stuff } <input type="image" name="submit" value="submit" src="submit.jpg" /> form is not catching... thats why I was wondering, maybe its a server setting being funky? i dont know.. Quote Link to comment https://forums.phpfreaks.com/topic/139573-best-way-to-check-for-form-submit/#findComment-730144 Share on other sites More sharing options...
castis Posted January 5, 2009 Share Posted January 5, 2009 put var_dump($_POST); before your if statement and see if it outputs anything. Quote Link to comment https://forums.phpfreaks.com/topic/139573-best-way-to-check-for-form-submit/#findComment-730148 Share on other sites More sharing options...
Maq Posted January 5, 2009 Share Posted January 5, 2009 Is it encapsulated in form tags? if(isset($_POST['submit'])) { echo "You submitted, wow!"; } </pre> <form method="POST" action="<?php%20echo%20%24_SERVER%5B'PHP_SELF'%5D;%20?>"> < Quote Link to comment https://forums.phpfreaks.com/topic/139573-best-way-to-check-for-form-submit/#findComment-730151 Share on other sites More sharing options...
flyhoney Posted January 5, 2009 Share Posted January 5, 2009 In reference to your original question, this is the way I usually do it. (obviously this won't work for every situation) <?php if (isset($_POST['action'])) { // do phpz } ?> <form method="post" action="index.php"> <input type="submit" name="action" value="Submit" /> </form> I never name my submit buttons 'submit' because this causes problems with javascript. Quote Link to comment https://forums.phpfreaks.com/topic/139573-best-way-to-check-for-form-submit/#findComment-730154 Share on other sites More sharing options...
PFMaBiSmAd Posted January 5, 2009 Share Posted January 5, 2009 Read this link to find out how to use an image as a submit button so that it works in all browsers - http://us.php.net/manual/en/faq.html.php#faq.html.form-image Quote Link to comment https://forums.phpfreaks.com/topic/139573-best-way-to-check-for-form-submit/#findComment-730203 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.