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
Paco Torres
8,450 PointsRe-Displaying the Submission
When I submit the form with an invalid email, all the values I entered get preserved but the message. I don't understand why the message does not appear.
This is the beginning of my code:
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = trim($_POST["name"]);
$email = trim($_POST["email"]);
$message = trim($_POST["message"]);
<form method="post" action="contact.php">
<table>
<tr>
<th>
<label for="name">Name</label>
</th>
<td>
<input type="text" name="name" id="name" value="<?php if (isset($name)) { echo $name; } ?>">
</td>
</tr>
<tr>
<th>
<label for="email">Email</label>
</th>
<td>
<input type="text" name="email" id="email" value="<?php if (isset($email)) { echo $email; } ?>">
</td>
</tr>
<tr>
<th>
<label for="message">Message</label>
</th>
<td>
<textarea name="message" id="message"><?php if (isset($message)) { echo $message; } ?></textarea>
</td>
</tr>
<tr style="display: none;">
<th>
<label for="address">Address</label>
</th>
<td>
<input type="text" name="address" id="address">
<p>Humans (and frogs): please, leave this field blank.</p>
</td>
</tr>
</table>
<input type="submit" value="Send">
</form>
Thank you!
2 Answers
Paco Torres
8,450 PointsI'm sorry. I tried to format my question, but I did not success.
Updated: I success.
Paco Torres
8,450 PointsSolved! It was a silly little mistake:
if ($name == "" OR $email == "" OR $message = "") {
$error_message = "You must specify a value for name, email address and message.";
}
I wrote $message = "" instead of $message == ""