Here is my HTML and javascript validation. I used checklist to select the projects but i am getting the mails with only first element value of checkbox or not getting any thing. I will post PHP code also. I am working on this check list thing first time please help me to get this thing done.
jQuery(".form-js-contact").submit(function() {
var thisform = jQuery(this);
jQuery('.required-error', thisform).remove();
var aname = jQuery("#aname").val();
var amail = jQuery("#amail").val();
var aphone = jQuery("#aphone").val();
var acomments = jQuery("#acomments").val();
var color = jQuery("#color").val();
var psubject = jQuery("#psubject").val();
var data = {
'aname': aname,
'amail': amail,
'aphone': aphone,
'acomments': acomments,
'psubject': psubject,
'color': color
};
if (aname == "") {
jQuery("#aname").after('<span class="form-description required-error">Required field.</span>');
} else {
jQuery("#aname").parent().find('.required-error').remove();
}
if (amail == "") {
jQuery("#amail").after('<span class="form-description required-error">Required field.</span>');
} else {
jQuery("#amail").parent().find('.required-error').remove();
}
if (aphone == "") {
jQuery("#aphone").after('<span class="form-description required-error">Required field.</span>');
} else {
jQuery("#aphone").parent().find('.required-error').remove();
}
if (acomments == "") {
jQuery("#acomments").after('<span class="form-description required-error">Required field.</span>');
} else {
jQuery("#acomments").parent().find('.required-error').remove();
}
if (aname != "" && amail != "" && aphone != "" && acomments != "") {
jQuery.post("contact_us_contact.php", data, function(result) {
if (result == "done") {
thisform.prepend("<div class='alert-message success-contact'><p><strong>Thank you " + name + "!</strong> We'll be in touch real soon .</p></div>");
jQuery("#aname").val("");
jQuery("#amail").val("");
jQuery("#aphone").val("");
jQuery("#acomments").val("");
}
});
}
return false;
});
This is my HTML code
<form class="form-style form-js-contact" action="contact_us_contact.php" method="post">
<input type="hidden" name="psubject" id="psubject" value="Enquiry from Contact Page">
<div class="col-md-6 col-lg-6" >
<input class=required-item value="" name=aname id=aname aria-required=true placeholder="Your Name*"></div>
<div class="col-md-6 col-lg-6" ><input type=email class=required-item id=amail name=amail value="" aria-required=true placeholder="Your Email*"></div>
<div class="col-md-6 col-lg-12" ><input class=required-item aria-required=true id=aphone name=aphone value="" placeholder="Your Phone*"></div>
<div class="col-md-3" style="margin-bottom:10px; "><h4>Projects Interested</h4></div>
<div class="col-md-2" ><input name="color[]" id="color" class="check" type="checkbox" value="Amairo">Amairo</div>
<div class="col-md-2" ><input name="color[]" id="color" class="check" type="checkbox" value="Tatvam">Tatvam</div>
<div class="col-md-2" ><input name="color[]" id="color" class="check" type="checkbox" value="Vedam">Vedam</div>
<div class="col-md-6 col-lg-12" >
<textarea name="acomments" id="acomments" class=required-item aria-required=true placeholder="Type Your Message*"></textarea></div>
<div class="col-md-6 col-lg-6" >
<input style=font-size:16px name=submit type=submit value="Send Enquiry" class="submit_buttom buttonColor" id="Main_Contact_Form"></div>
</form>
This is my PHP
<?php
function clean_text($text = '') {
$text = trim($text);
$text = strip_tags($text);
$text = addslashes($text);
$text = htmlspecialchars($text);
return $text;
}
if (!$_POST) {
die();
} else {
if (empty($_POST["aname"]) && empty($_POST["aphone"]) && empty($_POST["amail"]) && empty($_POST["acomments"])) {
echo "all_empty";
} else if (empty($_POST["aname"])) {
echo "empty_name";
} else if (empty($_POST["amail"])) {
echo "empty_mail";
} else if (empty($_POST["aphone"])) {
echo "empty_phone";
} else if (empty($_POST["acomments"])) {
echo "empty_Comments";
} else {
$your_email = "my@domain";
$aname = clean_text($_POST["aname"]);
$amail = clean_text($_POST["amail"]);
$aphone = clean_text($_POST["aphone"]);
$acomments = clean_text($_POST["acomments"]);
$wname = $_POST['color'];
$psubject = clean_text($_POST["psubject"]);
$subject = "$psubject";
$headers = "From: leads@domain.in";
$msg = "New Message \n\r";
$msg .= "Name : \t $aname \r\n";
$msg .= "Email : \t $amail \r\n";
$msg .= "Phone : \t $aphone \r\n";
$msg .= "Message : \t $acomments \r\n";
if (isset($_POST['wname'])) {
$msg .= "You chose the following color(s): \r\n";
$msg .= "<ul> \r\n";
foreach ($wname as $color) {
$msg .= "<li>" . $color . "</li> \r\n";
}
$msg .= "</ul>";
} // isset
echo "done";
$done = @mail($your_email, $subject, $msg, $headers);
}
}
?>
Aucun commentaire:
Enregistrer un commentaire