dmccabe Posted June 19, 2008 Share Posted June 19, 2008 I have been using this code to check if the submit button on a form has been clicked. if (isset($_POST['hoi'])) { However the problems is the 'hoi' isnt always set, so can I do something like: if (isset($_POST)) { Instead just so it checks if something has been posted? Quote Link to comment https://forums.phpfreaks.com/topic/110927-if-_post/ Share on other sites More sharing options...
rhodesa Posted June 19, 2008 Share Posted June 19, 2008 i always use this: if($_SERVER['REQUEST_METHOD'] == 'POST'){ Quote Link to comment https://forums.phpfreaks.com/topic/110927-if-_post/#findComment-569059 Share on other sites More sharing options...
waynew Posted June 19, 2008 Share Posted June 19, 2008 Either way works as long as you don't have other forms leading to that page. Quote Link to comment https://forums.phpfreaks.com/topic/110927-if-_post/#findComment-569061 Share on other sites More sharing options...
dmccabe Posted June 19, 2008 Author Share Posted June 19, 2008 Either way works as long as you don't have other forms leading to that page. Which unfortunately I do, so how do I get round the issue? Quote Link to comment https://forums.phpfreaks.com/topic/110927-if-_post/#findComment-569064 Share on other sites More sharing options...
waynew Posted June 19, 2008 Share Posted June 19, 2008 Make sure that the hidden fields of each page leading to this page are different from each other so that you can distinguish between them. Then change if statement accordingly. One hiddenfield could be "edit". Another could be "new". Or whatever...? Quote Link to comment https://forums.phpfreaks.com/topic/110927-if-_post/#findComment-569065 Share on other sites More sharing options...
rhodesa Posted June 19, 2008 Share Posted June 19, 2008 so you have a page that handles posts from several different pages? you can differentiate with either a hidden input element or with a GET variable. just use a standard name across all the forms (like 'source') and then you can use a switch statement on your form processing page Quote Link to comment https://forums.phpfreaks.com/topic/110927-if-_post/#findComment-569066 Share on other sites More sharing options...
wildteen88 Posted June 19, 2008 Share Posted June 19, 2008 I have been using this code to check if the submit button on a form has been clicked. if (isset($_POST['hoi'])) { However the problems is the 'hoi' isnt always set, so can I do something like: if (isset($_POST)) { Instead just so it checks if something has been posted? What is $_POST['hoi'] associated to in your form? You should give your submit button a name, then reference the submit buttons name in the $_POST array instead to check to see if the form has been submitted. Quote Link to comment https://forums.phpfreaks.com/topic/110927-if-_post/#findComment-569402 Share on other sites More sharing options...
lemmin Posted June 19, 2008 Share Posted June 19, 2008 You should give your submit button a name, then reference the submit buttons name in the $_POST array instead to check to see if the form has been submitted The name of the submit button won't get sent in IE if the user activates the submit button by pressing enter. Quote Link to comment https://forums.phpfreaks.com/topic/110927-if-_post/#findComment-569408 Share on other sites More sharing options...
Stephen Posted June 19, 2008 Share Posted June 19, 2008 Then maybe the user shouldn't be lazy and just click a stupid button! And then switch to FF! Heh jay kay. But I guess you could check hidden input as one person said, like <input type="hidden" name="hoi" value="hoi" />. Quote Link to comment https://forums.phpfreaks.com/topic/110927-if-_post/#findComment-569410 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.