Dtp1337 Posted October 4, 2012 Share Posted October 4, 2012 Can anyone provide me with the codes for these validation requirments. Names are not empty strings and are not numeric. They are also less than 20 characters long.###### contains a valid entry.Age is between 0 and 120.Output the data that was entered if all entries are valid, if an entry is invalid, print an error message describing data errors. Link to comment Share on other sites More sharing options...
Ixzion Posted October 4, 2012 Share Posted October 4, 2012 I'm not gonna do your homework for you, but I'll give you some pointers in the right direction. Using the php.net manual will help a lot. 1. Look up empty and is_numeric.2. I don't know what this means.3. Use comparison operators (==, >, <, etc).4. You'll probably want something like if ($this && $that && $other) { do something } Link to comment Share on other sites More sharing options...
Dtp1337 Posted October 4, 2012 Author Share Posted October 4, 2012 (edited) Could I get examples of those? please? Your not doing the work. I'm looking up the code to use. If you know a webpage that lists examples of those please post it. Also do I do all the validation like this? check_input($_POST['Fname'], "Enter your first name!")^minus this and + whatever I'm validating the Form information with. Edited October 4, 2012 by Dtp1337 Link to comment Share on other sites More sharing options...
niche Posted October 4, 2012 Share Posted October 4, 2012 (edited) lxzion is on point. You're on record as being a student, but that's OK. Just be reminded that this is a learning site and that you need to post code with your question or ask a terminology question so you can search for more info. Edited October 4, 2012 by niche Link to comment Share on other sites More sharing options...
niche Posted October 4, 2012 Share Posted October 4, 2012 (edited) Validate your code at : http://www.w3schools...eb_validate.asp html tutorials: http://www.w3schools...tml/default.asp EDIT: You don't validate php. You validate the html that it can produce. Edited October 4, 2012 by niche Link to comment Share on other sites More sharing options...
Dtp1337 Posted October 4, 2012 Author Share Posted October 4, 2012 (edited) Also the ###### says the normal word for gender is valid check. It is php validation of Form Input. Such as the htmlentities and htmlspecialchars ... How is asking for the code commands that do what I asked, end with him doing any of my work? By that with me being a student, how is me asking for specific code piece any different then googling it. And now that I've took a minute to read his answer I see that he ment to "look up" those words. I didn't understand completely. Edited October 4, 2012 by Dtp1337 Link to comment Share on other sites More sharing options...
niche Posted October 4, 2012 Share Posted October 4, 2012 (edited) Dtp1337, it's best to give a little to get a little just like you did in your first topic. So with that in mind, what have you actually written that validates "Names are not empty strings and are not numeric"? It's going to involve an if statement. Edited October 4, 2012 by niche Link to comment Share on other sites More sharing options...
Dtp1337 Posted October 4, 2012 Author Share Posted October 4, 2012 I'm looking for what to write. What I have found is this http://myphpform.com/validating-forms.php but individually check each input variable with the list I posted above. Or can I use the function to individually validate each variable? Link to comment Share on other sites More sharing options...
niche Posted October 4, 2012 Share Posted October 4, 2012 (edited) OK, how are you going to check whether the user submitted an empty value? I didn't see that in the link. Edited October 4, 2012 by niche Link to comment Share on other sites More sharing options...
Dtp1337 Posted October 4, 2012 Author Share Posted October 4, 2012 (edited) Would this be considered checking for empty? check_input($_POST['Fname'], "Enter your first name!") It says that this sends an error if the blank is still empty when submitted. ^ ^ ^but this is a function for all variables inputed. Can I make a function that checks them individually or do I have to manually do it, if so what code would i use to do so? example !empty(is_numeric($_POST['yourname'])); ??? < is that close? if yes how do I specify how many characters are allowed^does ! make it "is not empty"? Edited October 4, 2012 by Dtp1337 Link to comment Share on other sites More sharing options...
niche Posted October 4, 2012 Share Posted October 4, 2012 Where did you get that function? It's not in the manual. Link to comment Share on other sites More sharing options...
Dtp1337 Posted October 4, 2012 Author Share Posted October 4, 2012 that link i gave http://myphpform.com...ating-forms.php Link to comment Share on other sites More sharing options...
niche Posted October 4, 2012 Share Posted October 4, 2012 empty() works. http://us2.php.net/manual/en/function.empty.php Link to comment Share on other sites More sharing options...
Dtp1337 Posted October 4, 2012 Author Share Posted October 4, 2012 if (is_numeric($Fname)) || (is_numeric($Lname)) { echo "'{$Fname}' is numeric", PHP_EOL; echo "'{$Lname}' is numeric", PHP_EOL; } else { echo "'{$Fname}' is not numeric", PHP_EOL; echo "'{Lname}' is not numeric", PHP_EOL; } would that be right? 1 Link to comment Share on other sites More sharing options...
niche Posted October 4, 2012 Share Posted October 4, 2012 (edited) No. Run it and fix the errors. They're will be easy to fix. Hint: Why put a comma and PHP_EOL outside the dbl quotes? Edited October 4, 2012 by niche Link to comment Share on other sites More sharing options...
Ingolme Posted October 4, 2012 Share Posted October 4, 2012 Hint: Why put a comma and PHP_EOL outside the dbl quotes?Because the comma indicates another argument for the echo command and PHP_EOL is the PHP constant to be echoed. 1 Link to comment Share on other sites More sharing options...
niche Posted October 4, 2012 Share Posted October 4, 2012 (edited) Ingolme, you're two for two with me in the last few minutes! I've not seen a constant used that way before. so borrowing from http://www.w3schools...sc_constant.asp I produced this quick learning script: <?phpdefine("GREETING","Hello you! How are you today?");echo "xyz " ,GREETING;?> See how that works Dtp1337. I just "validated" what I learned with a quick little script with a little prompting from the fox. I didn't ask him to put it all together (though for a moment I was mildly disappointed for not knowing), but I knew if I put a quick script together and it didn't "work", I could post my code and I'd get help and possibly some mild harmless ridicule. No harm. No foul. FWIW, I'm calling it a night. Thanks for the thread. Also, Dtp1337 I gave you your first like. I learned something new because of you. This forum and the people that participate in it are the greatest! Edited October 4, 2012 by niche Link to comment Share on other sites More sharing options...
Dtp1337 Posted October 4, 2012 Author Share Posted October 4, 2012 I dunno what to do with it now. Heres what I got as a whole... <!DOCTYPE HTML> <?php /********************************************** Author: Dylan T. Patterson* Filname: CISP1720-dpatter3-LAB6.php* Assignment: CISP1720-dpatter3-LAB6.php* Date: 10/3/2012* Description: Displays and validates First and Last Name, ######, and Age. *********************************************/ ?> <html> <head> <meta a http-equiv="Content-Type" content="text/html; charset=utf-8"> <title> CISP1720 Lab 6</title> </head> <h1> Lab 6 </h1> <h3> Information provided.</h3> <body> <p> <?php $Fname = empty($_POST['Fname'], "Enter your first name!"); $Lname = empty($_POST['Lname'], "Enter your last name!"); $###### = ($_POST['######'], "Enter your gender!"); $Age = ($_POST['Age'], "Enter your age!"); if (is_numeric($Fname)) || (is_numeric($Lname)) { echo "'{$Fname}' is numeric"; echo "'{$Lname}' is numeric"; } else { echo "'{$Fname}' is not numeric", PHP_EOL; echo "'{Lname}' is not numeric", PHP_EOL; } if (!filter_input(INPUT_POST, '######', FILTER_SANITIZE_STRING)) { echo "###### is not valid"; } else { echo "###### is valid"; } echo "<p> First Name: $Fname </p> \n"; echo "<p> Last Name: $Lname </p> \n"; echo "<p> ######: $###### </p> \n"; echo "<p> Age: $Age </p> \n"; ?> ---------------------------------------------------------------------------------------------------------- <!DOCTYPE HTML> <?php /********************************************** Author: Dylan T. Patterson* Filname: CISP1720-dpatter3-LAB06-F.php* Assignment: CISP1720-dpatter3-LAB06-F.php* Date: 10/3/2012* Description: Form program passing information to a Php program to process. *********************************************/ ?> <html> <head> <meta a http-equiv="Content-Type" content="text/html; charset=utf-8"> <title> CISP1720 Lab 6</title> </head> <h1> Lab 6 </h1> <h3> Input Form </h3> <body> <form action="CISP1720-dpatter3-Lab06.php" method="post"> <p> Please provide your First Name. <input name="Fname" type="text" /><p/> <p> Please provide your Last Name. <input name="Lname" type="text" /><p/> <p> Please provide your ######. <input name="######" type="text" /><p/> <p> Please provide your Age. <input name="Age" type="text" /><p/> <input type="submit" name="Submit" id="Submit" value="Submit"></body></html> Link to comment Share on other sites More sharing options...
niche Posted October 4, 2012 Share Posted October 4, 2012 What's your question? The toughest part of self-directed learning is responsibility for the questions not just the answers. IMO. I feel for you, but have to hold you to asking something more specific than "what's next?". Link to comment Share on other sites More sharing options...
justsomeguy Posted October 4, 2012 Share Posted October 4, 2012 You're not using empty correctly here: $Fname = empty($_POST['Fname'], "Enter your first name!"); empty only takes a single parameter, the variable to test. You should use it in an if statement like you're doing with is_numeric. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now