Created
December 27, 2012 02:13
-
-
Save anonymous/4384872 to your computer and use it in GitHub Desktop.
Hello. I have a contact form that works via PHP. I want to update the code to make all fields REQUIRED. So that if someone leaves a text box empty and clicks 'SEND', a red REQUIRED will appear in the empty text field, and not submit the form. Below is the HTML and PHP.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HTML: | |
<form action="send_email.php" method="post" id="contact-form"> | |
<div class="contact-form-input contact-input-wrapper"> | |
<label class="contact-label">Name:</label> | |
<input type="text" name="name" class="required" /> | |
</div> | |
<div class="contact-form-input contact-input-wrapper"> | |
<label class="contact-label">E-mail:</label> | |
<input type="text" name="email" class="required email" /> | |
</div> | |
<div class="contact-form-textarea contact-input-wrapper"> | |
<label class="contact-label">Letter:</label> | |
<textarea name="question" rows="" cols="" class="required"></textarea> | |
</div> | |
<input type="submit" name="Submit" value="Send" class="button send-button"> | |
<div class="clear"></div> | |
</form> | |
HERE'S THE PHP: | |
<?php | |
// from the form | |
$name = trim(strip_tags($_POST['name'])); | |
$email = trim(strip_tags($_POST['email'])); | |
$question = htmlentities($_POST['question']); | |
// set here | |
$subject = "HAYLEYHENDRIX.com - Letter From Site."; | |
$to = "email@gmail.com"; | |
$body = <<<HTML | |
Name: $name <br /> | |
Email: $email <br /> | |
Message: $question | |
HTML; | |
$headers = "From: $email\r\n"; | |
$headers .= "Content-type: text/html\r\n"; | |
// send the email | |
mail($to, $subject, $body, $headers); | |
// Shows is email was sent. | |
echo "<h2>Email Sent Successfully</h2><p>I will be in touch within the next 24-48 hours. Thanks for reaching out to me.</p>"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment