Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML

Finish the HTML Form example

Finish the HTML Form example now were can i go to get the PHP files or tell me how to do it for the form can work?

4 Answers

yes buy they tech you how to do a form.php. The one i was doing it was html they never finish how to make that form into php so it can work. So what happened with what a learn i will love to finish and make it work.\

<form action="index.html" method="post">

    <h1>Sign Up</h1>

    <input type="text" id="name" name="user_name">
    <input type="email" id="mail" name="user_email">
    <input type="password" id="password" name="user_password">

    <textarea id="bio" name="user_bio"></textarea>

    <button type="submit">Sign Up</button>

  </form>
Hugo Paz
Hugo Paz
15,622 Points

You still use your HTML, basically you use PHP or another server side language to process the form. So what you learned here is relevant. Using your form as an example with php, it would look like this:

<form method="post" action="nameOfPhpFileHere">
    <h1>Sign Up</h1>

    <input type="text" id="name" name="user_name">
    <input type="email" id="mail" name="user_email">
    <input type="password" id="password" name="user_password">

    <textarea id="bio" name="user_bio"></textarea>

    <button type="submit">Sign Up</button>

  </form>

As you can see, you just add 2 attributes to the form tag. Then you need a file named nameOfPhpFileHere which will process the form.

nameOfPhpFileHere.php rigth?

is this correct ?

<?php $errors = ''; $myemail = 'josue@tmomail.net'; if(empty($_POST['name']) || empty($_POST['mail']) || empty($_POST['password']) || empty($_POST['bio']))

{ $errors .= "\n Error: all fields are required"; }

$name = $_POST['name']; $mail = $_POST['mail']; $password = $_POST['password']; $bio = $_POST['bio'];

if( empty($errors)) { $to = $myemail; $email_subject = "Quick Booking Form: $name"; $email_body = "You have received a new message. ". " Here are the details:\n Name: $name \n mail: $mail \n password: $password \n bio: $bio";

$headers = "From: $myemail\n"; 
$headers .= "Reply-To: $email_address";

mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: contact-form-thank-you.html');

} ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Quick Form</title> </head>

<body> <!-- This page is displayed only if there is some error --> <?php echo nl2br($errors); ?>

Hugo Paz
Hugo Paz
15,622 Points

Yes that should be enough to make a working example.

for some reason when i try it tell me all fields are required .. then i remove that and it works but when i received i just get do input names only i do not get the things i type.

Hugo Paz
Hugo Paz
15,622 Points

You need to use the name field not the id.

substitute this:

$name = $_POST['name']; 
$mail = $_POST['mail']; 
$password = $_POST['password']; 
$bio = $_POST['bio'];

with this:

$name = $_POST['user_name']; 
$mail = $_POST['user_mail']; 
$password = $_POST['user_password']; 
$bio = $_POST['user_bio'];

<html> <head> <meta charset="utf-8"> <title>HTML Forms</title> </head> <body>

<form action="index.html" method="post">

  <label for="name">Name:</label>
  <input type="text" id="name" name="user_name">

      <label for="email">Email:<label>
   <input type="email" id="mail" name="user_email">

        <label for="password">Password</label>
   <input type="password" id="password" name="user_password">


  <label for="comment">Comment:</label>
  <textarea id="comment" name="user_comment"></textarea>

  <button type="submit">Submit Comment</button>
</form>

</body> </html>