sgtmcnoobles Posted November 23, 2016 Share Posted November 23, 2016 (edited) i have an assignment where i have to creat a web form that accepts a name and emaoil and posts to its self and on submission it should vailidate if its not valid a error should be loaded into session and vaild fields should be filled with previous value. Im just trying to get the input boxes to show up right now and im not sure why they arent.form1.php Edited November 23, 2016 by sgtmcnoobles Quote Link to comment https://forums.phpfreaks.com/topic/302603-input-fields-are-not-showing-up/ Share on other sites More sharing options...
Solution cyberRobot Posted November 23, 2016 Solution Share Posted November 23, 2016 It looks like your form is created within the setassign3() function. Where is the function being called? Also note that $this is used for class methods. As far as I can tell, setassign3() is just a user-defined function. Quote Link to comment https://forums.phpfreaks.com/topic/302603-input-fields-are-not-showing-up/#findComment-1539623 Share on other sites More sharing options...
cyberRobot Posted November 23, 2016 Share Posted November 23, 2016 For the sake of others, the code from form1.php can be found below. Note that some of the formatting was lost when I pasted the code. So I quickly added some indents. Hopefully everything is correct. <?php session_start(); ?> <?php function setTop(){ $_top = ""; $_top = "<!doctype html>"; $_top .= "<html>"; $_top .= "<head>" . $this->_headSection; $_top .= "<title>" . $this-> _title . "</title>"; $_top .= "</head>"; $_top .= "<body>"; $this-> _top = $_top; } function setassign3(){ // function creates the form $_assign = "<form action= '' method='POST' method='SESSION'>"; //calls form1.php and posts $_assign .= "<p>Enter Name, and a Number and Email</p>"; $_assign .= "<p>Name:</p><input type = 'text' name = 'name' id = 'name' value = '' >";//field for the name $_assign .= "<p>Number:</p><input type='number' name='number' id = 'number' value = '' >";//field for number $_assign .= "<p>Email:</p><input type='email' name='email' id = 'email' value = '' >";//field for number $_assign .= "<p></P><input type='submit' value='submit' >"; $_assign .= "</form>"; $this-> _assign = $_assign; } //if($_SERVER["REQUEST_METHOD"] == "POST"){ // code from http://stackoverflow.com/questions/22265509/why-should-we-use-if-serverrequest-method-post if (isset($_POST['name']) && !empty($_POST['name'])){// http://stackoverflow.com/questions/13045279/if-isset-post $name= filter_var($_POST['name'], FILTER_SANITIZE_STRING); print($name); } else { print "please enter your name"; } if($_SERVER["REQUEST_METHOD"] == "POST"){ if (isset($_POST['email']) && !empty($_POST['email'])){ //http://stackoverflow.com/questions/13045279/if-isset-post filter_var($_POST['email'], FILTER_VALIDATE_INT); $email = filter_var($_POST['email'], FILTER_SANITIZE_NUMBER_INT); print $email; }else{ print "<P>please enter a valid number</P>"; } } if($_SERVER["REQUEST_METHOD"] == "POST"){ // code from http://stackoverflow.com/questions/22265509/why-should-we-use-if-serverrequest-method-post if (isset($_POST['email']) && !empty($_POST['email'])){// http://stackoverflow.com/questions/13045279/if-isset-post $email= filter_var($_POST['email'], FILTER_SANITIZE_STRING); print($email); } else { print "please enter a valid email"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/302603-input-fields-are-not-showing-up/#findComment-1539624 Share on other sites More sharing options...
ginerjm Posted November 23, 2016 Share Posted November 23, 2016 (edited) I think you should learn how to write better English before embarking upon a new language. I counted 11 spelling errors. PS - most people post their code HERE and not somewhere else where we would have to gamble on whether it is a 'bad' link or not. Edited November 23, 2016 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/302603-input-fields-are-not-showing-up/#findComment-1539625 Share on other sites More sharing options...
ginerjm Posted November 23, 2016 Share Posted November 23, 2016 Oh My! Did you really write this based upon the knowledge you are getting in your class? I assume you are in a class of some kind since you have an assignment that you seek our help on. Maybe you should have listened better in class. Why do you think you have to check the request method before testing each and every input value? Wouldn't one be sufficient? You are copying code and have forgotten to change the email checker to whatever number value you are trying to have the user provide. Your form tag is wrong. Look at it again please. Most modern html guides tell you to use the label tag with a corresponding id attribute to connect it to the input tag it is labeling. As for the "vaild fields should be filled with previous value" problem - you need to use a php var in the value attribute of each input tag and pass those vars to the html code function. Have fun! Quote Link to comment https://forums.phpfreaks.com/topic/302603-input-fields-are-not-showing-up/#findComment-1539627 Share on other sites More sharing options...
cyberRobot Posted November 23, 2016 Share Posted November 23, 2016 In case it's of interest, I added a few things to ginerjm's points below. Most modern html guides tell you to use the label tag with a corresponding id attribute to connect it to the input tag it is labeling. The <label> tag can also wrap around the input field. That way you don't need to worry about the id and for attributes. Your form tag is wrong. Look at it again please. The W3C has a great tool for validating HTML code here: http://validator.w3.org/ Quote Link to comment https://forums.phpfreaks.com/topic/302603-input-fields-are-not-showing-up/#findComment-1539629 Share on other sites More sharing options...
ginerjm Posted November 23, 2016 Share Posted November 23, 2016 The <label> tag can also wrap around the input field. That way you don't need to worry about the id and for attributes. I did not know that! My day is complete now! Quote Link to comment https://forums.phpfreaks.com/topic/302603-input-fields-are-not-showing-up/#findComment-1539630 Share on other sites More sharing options...
cyberRobot Posted November 23, 2016 Share Posted November 23, 2016 I did not know that! My day is complete now! Yep, that was something I recently learned too. It's made my code so much cleaner. Quote Link to comment https://forums.phpfreaks.com/topic/302603-input-fields-are-not-showing-up/#findComment-1539631 Share on other sites More sharing options...
sgtmcnoobles Posted November 23, 2016 Author Share Posted November 23, 2016 I think you should learn how to write better English before embarking upon a new language. I counted 11 spelling errors. PS - most people post their code HERE and not somewhere else where we would have to gamble on whether it is a 'bad' link or not. ^ This is why im not an English major lol. Also I didnt know about just posting the code so ill do that next time Oh My! Did you really write this based upon the knowledge you are getting in your class? I assume you are in a class of some kind since you have an assignment that you seek our help on. Maybe you should have listened better in class. Why do you think you have to check the request method before testing each and every input value? Wouldn't one be sufficient? You are copying code and have forgotten to change the email checker to whatever number value you are trying to have the user provide. Your form tag is wrong. Look at it again please. Most modern html guides tell you to use the label tag with a corresponding id attribute to connect it to the input tag it is labeling. As for the "vaild fields should be filled with previous value" problem - you need to use a php var in the value attribute of each input tag and pass those vars to the html code function. Have fun! ^ I listen just fine in class. listing =/= the ability to do something. I, for the most part, understand what everything does im just awful at starting with nothing and making a page or whatever. im more of a media development person but we have to take webdesign classes to graduate. but i just moved the html out of the php and it works now, thats all i wanted Quote Link to comment https://forums.phpfreaks.com/topic/302603-input-fields-are-not-showing-up/#findComment-1539632 Share on other sites More sharing options...
ginerjm Posted November 23, 2016 Share Posted November 23, 2016 You must of done more than "move the html out of the php" to make that mess work. If you have to take "webdesign classes" to graduate, they should make you also take an English class as demonstrated by this line: " listing =/= the ability to do something." What does that (apparent) sentence mean? Even if they don't require you to write good English, your future employer might. I know if you worked for me in my previous life you would have had to write better than you have here get/keep any job. Quote Link to comment https://forums.phpfreaks.com/topic/302603-input-fields-are-not-showing-up/#findComment-1539633 Share on other sites More sharing options...
sgtmcnoobles Posted November 23, 2016 Author Share Posted November 23, 2016 You must of done more than "move the html out of the php" to make that mess work. If you have to take "webdesign classes" to graduate, they should make you also take an English class as demonstrated by this line: " listing =/= the ability to do something." What does that (apparent) sentence mean? Even if they don't require you to write good English, your future employer might. I know if you worked for me in my previous life you would have had to write better than you have here get/keep any job. mate, its a message board I'm not writing a doctorate shorthand is ok. As far as " listing =/= the ability to do something." just because i do not know where my error is doesn't mean i didn't listen. you've NEVER asked for help from a professor?!?!? that impressive. Also "write good English" isnt proper English FYI Quote Link to comment https://forums.phpfreaks.com/topic/302603-input-fields-are-not-showing-up/#findComment-1539634 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.