Does anyone know how to output this in PHP? Have much of the code already. I'm just entering the PHP realm.?
-
Take this HTML form: <html> <body> <form action="age_form_submit.php" method="POST"> <div><label for="first_name">First Name:</label> <input type="text" name="first_name" size=30></div> <div><label for="last_name">Last Name:</label> <input type="text" name="last_name" size=30></div> <div><label for="age">Age:</label> <input type="text" name="age" size=2></div> <div><label for="submit"> </label> <input type="submit" value="Send It!"></div> </form> </body> </html> And save it as age_form.php on your server. Now, create a new document: ========================== <?php $adult=array('cigars', 'galavanting', 'voting', 'stuff from when you were a kid', 'old things'); $child=array('bubble gum', 'Teletubbies', 'thumb sucking'); // You'll probably want to do some stuff, here. ?> <html> <body> <!-- You'll want to do some more PHP, here --> </body> </html> ========================== And save it as age_form_submit.php on your server. Here is your goal: When a user completes and submits the form, age_form_submit.php should output: Hello [the submitted first name] [the submitted last name]! You like: [output this portion if the age is 18 or over] 1. cigars 2. galavanting 3. voting 4. stuff from when you were a kid 5. old things [output this portion if the age is less than 18] 1. bubble gum 2. Teletubbies 3. thumb sucking Use the appropriate HTML tags when outputting this data. Use foreach on some array (depending on the age of the user) to output the appropriate unordered list. All three form fields are required. If the user fails to fill out any of them, send her/him back to the form, output an error message, and make sure that the previously submitted values are visible in each form field
-
Answer:
The answerer above simply outputted the age. Assuming you're allowed to edit the HTML form to add some PHP, here is your completed 'work': age_form_submit.php: <?php session_start(); $adult = array('cigars', 'galavanting', 'voting', 'stuff from when you were a kid', 'old things'); $child = array('bubble gum', 'Teletubbies', 'thumb sucking'); if (isset($_POST["first_name"]) && isset($_POST["last_name"]) && isset($_POST["age"]) && !empty($_POST["first_name"]) && !empty($_POST["last_name"]) && !empty($_POST["age"])) { extract($_POST); } else { $_SESSION["error"] = "You need to fill out all three fields."; header("Location: age_form.php"); } ?> <html> <body> <?php echo "Hello " . $first_name . " " . $last_name . "! \n"; echo "You like: \n"; echo "<ul>\n"; if ($age < 18) { foreach($child as $action) { echo "<li>" . $action . "</li>"; } } else { foreach($adult as $action) { echo "<li>" . $action . "</li>"; } } ?> </body> </html> age_form.php: <?php session_start(); ?> <html> <body> <form action="age_form_submit.php" method="POST"> <div><label for="first_name">First Name:</label> <input type="text" name="first_name" size="30"></div> <div><label for="last_name">Last Name:</label> <input type="text" name="last_name" size="30"></div> <div><label for="age">Age:</label> <input type="text" name="age" size="2"></div> <div><label for="submit"> </label> <input type="submit" value="Send It!"></div> </form> <?php if (isset($_SESSION["error"])) { echo $_SESSION["error"]; unset($_SESSION["error"]); unset($_SESSION); session_destroy(); } ?> </body> </html>
Clugswor... at Yahoo! Answers Visit the source
Other answers
you have to post the input from the form to variables within age_form_submit.php . <?php // start [ age_form_submit.php ] $firstname = $_POST[first_name]; ?> then use the variable in html layout <p><?php $firstname ?></p>
Mark O
Related Q & A:
- Does anyone know why sometimes I pig out for a few days, then other days i can't eat anything at all?Best solution by Yahoo! Answers
- Does anyone know how I can get bruins tickets and train tickets as a package deal and where I could do this?Best solution by Yahoo! Answers
- Does anyone know how much it costs for an adult to go ice skating in Blackburn?Best solution by Yahoo! Answers
- Does anyone know how I can get a scholarship to study abroad?Best solution by usnews.com
- Does anyone know how I can get a football trial?Best solution by answers.yahoo.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.