- This topic is empty.
-
AuthorPosts
-
January 2, 2017 at 7:07 am #249565
chauhanheena
ParticipantHi
I’m trying to create a simple html/php contact form. below is the code:html
<div class="col-sm-8"> <div id="message"></div> <form method="post" action="html_form_send.php" name="contactform" id="contactform"> <fieldset> <input name="name" type="text" id="name" placeholder="Your Name*"/> <input name="email" type="text" id="email" placeholder="Your Email*"/> </fieldset> <fieldset> <p class="antispam">Leave this empty:<input name="url" /></p> <textarea name="comments" cols="40" rows="3" id="comments" placeholder="Your Message*"></textarea> </fieldset> <input type="submit" class="submit" id="submit" value="Send Message" /> </form> </div>
php
<?php if(isset($_POST['url']) && $_POST['url'] == ''){ // CHANGE THE TWO LINES BELOW $email_to = "[email protected]"; $email_subject = "Contact form on abc Website"; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['name']) || !isset($_POST['email']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $name = $_POST['name']; // required $email_from = $_POST['email']; // required $comments = $_POST['comments']; // required $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Name: ".clean_string($name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; $recipient = "[email protected]"; // create email headers $headers = 'From: '.$recipient."\r\n". 'Reply-To: '.$recipient."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); header("Location:http://www.abc.com/"); ?> <!-- place your own success html below --> header("Location:http://www.abc.com/"); <?php } die(); ?>
January 2, 2017 at 7:20 am #249567damcel
ParticipantWhat exactly is not working?
Please post your client side validation and JS as well, could be that too, we never know:-)
January 2, 2017 at 7:25 am #249568chauhanheena
Participantthis is all the code that i have for the contact form
the email is sent to the specified email id but validation is not done.
Also after submit, it is directed to http://www.abc.comAll i want is if the fields are empty, the an error message should display in the ‘message’ div
and if the fields are successfully filled, the the submit should be successful and a success message should display in the message div
January 2, 2017 at 8:17 am #249572damcel
ParticipantHere you go, try and submit the form without entering data:-)
You have the client side validation JS and under that, there is the php(commented ouit).
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.