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

General Discussion

Creating Input Fields & Contact Form in PHP

Hello:

my contact-process.php:

<?php

//echo "I have infromation from a form. Now What?";

var_dump($_POST);

?>

returns:

array(0) { }

I would like it to return an array with the form variables. Here is my contact.php code:

<?php

if ($_SERVER["REQUEST_METHOD"] == "POST") {

$firstName = $_POST["firstName"];
$lastName = $_POST["lastName"];
$addressLine1 = $_POST["addressLine1"];
$addressLine2 = $_POST["addressLine2"];
$city =  $_POST["city"];
$stateProvRegion =  $_POST["stateProvRegion"];
$zip =  $_POST["zip"];
$email =  $_POST["email"];
$phoneNumber =  $_POST["phoneNumber"];
$message =  $_POST["message"];
$email_body = "";
$email_body = $email_body . "Name: " . $name . "\n";
$email_body = $email_body . "Email: " . $email . "\n";
$email_body = $email_body . "Message: " . $message;

// TODO: Send Email

header("Location: contact.php?status=thanks");
exit;

} ?><?php $pageTitle = "Local Art Comissions"; $section = "contact"; include('inc/header.php'); ?>

<div class="section page">

    <div class="wrapper">

        <h1>Contact</h1>

         <?php if (isset($_GET["status"]) AND $_GET["status"] == "thanks") { ?>
            <p>Thanks for the email! I&rsquo;ll be in touch shortly!</p>
        <?php } else { ?>

        <p>We look forward to starting the comission process with you. Please fill out the contact form and Farber Art Services will get back to you about scheduling your free in-house consultation. If you have any specific questions/concerns or comments, be sure to leave a message in the field below. </p>

        <form method="post" action="contact-process.php">

            <table>
                <tr>
                    <th>
                        <label for="firstName">firstName</label> 
                    </th>
                    <td>
                        <input type="text" name"firstName" id="firstName">
                    </td>
                </tr>

                <tr>
                    <th>
                        <label for="lastName">lastName</label> 
                    </th>
                    <td>
                        <input type="text" name"lastName" id="lastName">
                    </td>
                </tr>

                <tr>
                    <th>
                        <label for="addressLine1">addressLine1</label> 
                    </th>
                    <td>
                        <input type="text" name"addressLine1" id="addressLine1">
                    </td>
                </tr>

                <tr>
                    <th>
                        <label for="addressLine2">addressLine2</label> 
                    </th>
                    <td>
                        <input type="text" name"addressLine2" id="addressLine2">
                    </td>
                </tr>

                <tr>
                    <th>
                        <label for="city">city</label> 
                    </th>
                    <td>
                        <input type="text" name"city" id="city">
                    </td>
                </tr>

                <tr>
                    <th>
                        <label for="stateProvRegion">StateProvenceRegion</label> 
                    </th>
                    <td>
                        <input type="text" name"stateProvRegion" id="stateProvRegion">
                    </td>
                </tr>

                <tr>
                    <th>
                        <label for="zip">zip</label> 
                    </th>
                    <td>
                        <input type="text" name"zip" id="zip">
                    </td>
                </tr>

                <tr>
                    <th>
                        <label for="email">email</label> 
                    </th>
                    <td>
                        <input type="text" name"email" id="email">
                    </td>
                </tr>

                <tr>
                    <th>
                        <label for="phoneNumber">phoneNumber</label> 
                    </th>
                    <td>
                        <input type="text" name"phoneNumber" id="phoneNumber">
                    </td>
                </tr>

                <tr>
                    <th>
                        <label for="message">Message</label> 
                    </th>
                    <td>
                        <textarea name"message" id="message"></textarea>
                    </td>
                </tr>
            </table>
            <input type="submit" value"Send" >

        </form> 
        <?php } ?>


    </div>
</div>

<?php include('inc/footer.php'); ?>

1 Answer

Hi William,

It looks like you are missing an equal sign after each of your "name" attributes. Also, with the value attribute on your submit button.