Davecnll Posted September 5, 2017 Share Posted September 5, 2017 Hi!! The day after tomorrow I've a HTML exam... Would you mind help me with this exercise?? I couldn't find the way to do it looking to the tutorials.. but if there is, and I missed it, let me now!! Create a HTML index.html containing a form: - with 2 text boxes to insert the name and the lastname; - a Submit button which sends the datas inserted by the user to a script php named namecontrol.php. Create a PHP page which has to visualize the datas sent from the form, as a list. Link to comment Share on other sites More sharing options...
Gabrielphp Posted September 5, 2017 Share Posted September 5, 2017 What does it reffers to when it says has to see the data as a list? You mean like a html <ul><li> or an array() in php and echo that? Link to comment Share on other sites More sharing options...
justsomeguy Posted September 5, 2017 Share Posted September 5, 2017 If it specifies a list, it probably means an HTML list. Link to comment Share on other sites More sharing options...
Davecnll Posted September 7, 2017 Author Share Posted September 7, 2017 (edited) Yeah I think so, it has to be a HTML list.. I'm ok with the first HTML form part, but I've no idea how to do the second one with php. Should be easy because, at university, we did only a basic part of php. Edited September 7, 2017 by Davecnll Link to comment Share on other sites More sharing options...
dsonesuk Posted September 7, 2017 Share Posted September 7, 2017 If it is just a singe first name, last name, just retrieve using $_GET or $_POST depending on whatever the method used in form, predefine html list, and echo out the result to that list. IF more than one user, you would have to store users, add new user, the loop through these stored names producing individual list item elements with these first names and last names. Link to comment Share on other sites More sharing options...
Gabrielphp Posted September 8, 2017 Share Posted September 8, 2017 So this is my answer for your problem: index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Name Control</title> </head> <body> <form method="post" action="namecontrol.php" > <input type="text" name="name" placeholder="Insert your name ..." /><br/> <input type="text" name="lastname" placeholder="Insert your last name ..." /><br/> <input type="submit" value="Submit" name="submit" /><br/> </form> </body> </html> namecontrol.php (HTML LIST) <?php if($_SERVER['REQUEST_METHOD'] == "POST") { if(isset($_POST['submit'])) { $name = $_POST['name']; $lastName = $_POST['lastname']; if(empty($name) || empty($lastName)) { echo "Please complete all fields to proceed !"; } else { echo "<ul>"; echo "<li>name: " . $name . " </li>"; echo "<li>lastname: " . $lastName . "</li>"; echo "</ul>"; } } } ?> namecontrol.php (ARRAY) <?php if($_SERVER['REQUEST_METHOD'] == "POST") { if(isset($_POST['submit'])) { $name = $_POST['name']; $lastName = $_POST['lastname']; if(empty($name) || empty($lastName)) { echo "Please complete all fields to proceed !"; } else { $array = array("name" => $name, "lastname" => $lastName); print_r($array); } } } ?> Link to comment Share on other sites More sharing options...
dsonesuk Posted September 8, 2017 Share Posted September 8, 2017 (edited) Seems wrong to ask for name then last name, name should represent full name, then you are asking for last name and repeating what you would have already provided. Should Be First name/s or forename/s and then last name in my opinion. Edited September 8, 2017 by dsonesuk 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