Jump to content

input fields are not showing up


sgtmcnoobles
Go to solution Solved by cyberRobot,

Recommended Posts

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 by sgtmcnoobles
Link to comment
Share on other sites

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";
    }
}
?>
Link to comment
Share on other sites

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 by ginerjm
Link to comment
Share on other sites

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!

Link to comment
Share on other sites

In case it's of interest, I added a few things to ginerjm's points below.  :happy-04:

 

 

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/

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.