bc2013 Posted August 29, 2008 Share Posted August 29, 2008 I am pretty new to php so this might be easy, Im not sure. I am trying to put together a simple site where I just need one template for the whole thing. I am trying to make a page with a form that has two text boxes and five drop down menus. Now what I need it to do is go to a page that tells them what they have inputted in the fields and send me an email telling me all the inputs. That part I sort of understand how to do but I need one more thing. I would like to have it tell the person if they have forgotten to input one of the fields and if any of the drop down menus and duplicated or missing. Maybe someone has an example or something. Thanks for your time. Quote Link to comment https://forums.phpfreaks.com/topic/121933-solved-help-with-a-simple-script/ Share on other sites More sharing options...
.josh Posted August 29, 2008 Share Posted August 29, 2008 just check if the input fields are missing (all inclusive example): <?php if(!$_POST['blah']) { echo "nothing entered <br />"; } ?> <form action = '' method = 'post'> <input type = 'text' name = 'blah'> <input type = 'submit' value = 'submit'> </form> Quote Link to comment https://forums.phpfreaks.com/topic/121933-solved-help-with-a-simple-script/#findComment-629281 Share on other sites More sharing options...
Eggzorcist Posted August 29, 2008 Share Posted August 29, 2008 This is fairly easy. I tend to do this in javascript as the user does not need to leave the page to find out if they are missing anything. However, a php alternative would having in the action: <?php if (!$_POST['TEXT1'] && !$_POST['TEXT2'] && !$_POST['RADIO1']){ //error message } ?> However that will never pinpoint the user's mistake. If you were to pinpoint the users mistake it's a bit more complicated. I'd use a jsp from a ready done jsp framework and mix it with php to not let the user click submit until everyting is spick & span. Guy above me beat me to it! Quote Link to comment https://forums.phpfreaks.com/topic/121933-solved-help-with-a-simple-script/#findComment-629284 Share on other sites More sharing options...
Wolphie Posted August 29, 2008 Share Posted August 29, 2008 just check if the input fields are missing (all inclusive example): <?php if(!$_POST['blah']) { echo "nothing entered <br />"; } ?> <form action = '' method = 'post'> <input type = 'text' name = 'blah'> <input type = 'submit' value = 'submit'> </form> Surely wouldn't $_POST['blah'] come back true regardless if it exists in the form? I could be wring but if it were me, I'd be checking the string length. if (empty($_POST['blah']) { // Error... } Quote Link to comment https://forums.phpfreaks.com/topic/121933-solved-help-with-a-simple-script/#findComment-629287 Share on other sites More sharing options...
kratsg Posted August 29, 2008 Share Posted August 29, 2008 This is fairly easy. I tend to do this in javascript as the user does not need to leave the page to find out if they are missing anything. However, a php alternative would having in the action: <?php if (!$_POST['TEXT1'] && !$_POST['TEXT2'] && !$_POST['RADIO1']){ //error message } ?> However that will never pinpoint the user's mistake. If you were to pinpoint the users mistake it's a bit more complicated. I'd use a jsp from a ready done jsp framework and mix it with php to not let the user click submit until everyting is spick & span. Guy above me beat me to it! This is bad practice. You can manipulate the post variables after the user has clicked to post (thereby javascript is useless for validation, but only a means of a quick-validation). You must STILL validate with PHP anyway. Quote Link to comment https://forums.phpfreaks.com/topic/121933-solved-help-with-a-simple-script/#findComment-629288 Share on other sites More sharing options...
.josh Posted August 29, 2008 Share Posted August 29, 2008 That won't pinpoint the user's mistake because you're throwing all 3 things into one condition. If you want to pinpoint it break it up into 3 conditions. That's not a bit more complicated, nor do you need to be throwing some jsp framework into the mix... and I would not advise using javascript for form validation except as a "bell and whistle" feature for users. That is, it's *more* convenient for them to have a popup before form submission, but you should still have php verify it, because it's on the server, where people can't circumvent your validation. just check if the input fields are missing (all inclusive example): <?php if(!$_POST['blah']) { echo "nothing entered <br />"; } ?> <form action = '' method = 'post'> <input type = 'text' name = 'blah'> <input type = 'submit' value = 'submit'> </form> Surely wouldn't $_POST['blah'] come back true regardless if it exists in the form? I could be wring but if it were me, I'd be checking the string length. if (empty($_POST['blah']) { // Error... } Try it and find out Quote Link to comment https://forums.phpfreaks.com/topic/121933-solved-help-with-a-simple-script/#findComment-629289 Share on other sites More sharing options...
Fadion Posted August 29, 2008 Share Posted August 29, 2008 @Wolphie. !$var returns true if the variable is empty. If the $var is empty it returns false, throw the NOT logical operator and you make it true to trigger the if(). It's the same as checking with empty() or $var == ''. Crayon Violent is right Quote Link to comment https://forums.phpfreaks.com/topic/121933-solved-help-with-a-simple-script/#findComment-629308 Share on other sites More sharing options...
bc2013 Posted August 29, 2008 Author Share Posted August 29, 2008 Thank you all for your input. I still am kinda lost but let me ask you from the example given: <?php if(!$_POST['blah']) { echo "blah is empty <br />"; } if(!$_POST['blah2']) { echo "blah2 is empty <br />"; } if(!$_POST['blah3']) { echo "blah3 is empty <br />"; } ?> <form action = '' method = 'post'> <input type = 'text' name = 'blah'> <input type = 'text' name = 'blah2'> <input type = 'text' name = 'blah3'> <input type = 'submit' value = 'submit'> </form> Is this valid? Also what about the five drop down fields if any are duplicated. Does anyone know how to do that? Thank you so much again for your guys help. Quote Link to comment https://forums.phpfreaks.com/topic/121933-solved-help-with-a-simple-script/#findComment-629317 Share on other sites More sharing options...
.josh Posted August 29, 2008 Share Posted August 29, 2008 You can refer to this thread for checking for duplicates. The only thing you really need to add to the solution(s) presented there is to convert all your dropdowns to a posted array or put them into an array. Quote Link to comment https://forums.phpfreaks.com/topic/121933-solved-help-with-a-simple-script/#findComment-629320 Share on other sites More sharing options...
DeanWhitehouse Posted August 30, 2008 Share Posted August 30, 2008 to make it more accurate dont use empty, but trim(); the posted data , and then check the string length. Quote Link to comment https://forums.phpfreaks.com/topic/121933-solved-help-with-a-simple-script/#findComment-629328 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.