HTML Contactform Security - php

I'm trying to send an E-Mail via HTML-Contactform.
Therefore I created this html:
<form id="contact_form" action="sendMail.php" method="post">
<input id="firstname" name="firstname" type="text" placeholder="Vorname" value="Firstname">
<input id="lastname" name="lastname" type="text" placeholder="Nachname" value="Lastname">
<input id="mail" name="mail" type="text" placeholder="E-Mail" value="firstname.lastname#web.de">
<textarea id="msg" name="msg" placeholder="Ihre Nachricht..." >Hallo</textarea>
<p id="error_print" class="hidden"></p>
<input id="contact_submit" type="submit" title="Senden">
</form>
I am checking the inputs via jQuery and sending it via Ajax to the PHP-File and print my errors to html.
$('#contact_submit').click(function(){
var that = $('#contact_form');
var first_name = $('#firstname').val();
var last_name = $('#lastname').val();
var mail = $('#mail').val();
var msg = $('msg').val();
if(first_name == "" || last_name == "" || mail == "" || msg == "")
{
$('#error_print').removeClass("hidden");
$('#error_print').text("Bitte füllen Sie alle Felder aus");
}
else
{
if( !isValidEmailAddress(mail) )
{
$('#error_print').removeClass("hidden");
$('#error_print').text("Keine korrekte Mail");
}
else
{
if( !$('#error_print').hasClass( "hidden" ) )
{
$('#error_print').addClass("hidden");
}
var url = that.attr('action'),
method = that.attr('method'),
data = {};
that.find('[name]').each(function(index, value)
{
var name = $(this).attr('name')
value = $(this).val();
data[name] = value;
});
//console.log(data);
$.ajax({
url: url,
type: method,
data: data,
success: function(response)
{
$('#error_print').removeClass("hidden");
$('#error_print').text("Mail wurde versendet");
},
error: function(error)
{
$('#error_print').removeClass("hidden");
$('#error_print').text("Fehler - Bitte erneut versuchen");
}
});
}
}
return false;
});
In my PHP I am sending the mail like this:
<?php
if(isset($_POST['firstname'], $_POST['lastname'], $_POST['mail'], $_POST['msg']))
{
$mail = htmlentities($_POST['mail'], ENT_QUOTES);
$firstname = htmlentities($_POST['firstname'], ENT_QUOTES);
$lastname = htmlentities($_POST['lastname'], ENT_QUOTES);
$msg = htmlentities($_POST['msg'], ENT_QUOTES);
$empfaenger = "empf#mydomain.de";
$betreff = "Kontaktaufname";
$from = "From: $fistname $lastname <$mail>";
$text = $msg;
//print_r($_POST);
mail($empfaenger, $betreff, $text, $from)
}?>
I do not know if this is the best way to do it. For that I read a lo about injection in mails. But I am not sure if my script is safe enough.

to send the mail you can try this below
<?php
ini_set("SMTP", "smtp.your_internet_service_provider.com");
ini_set("smtp_port", 25 );
ini_set("sendmail_from", "your_mail#example.com");
ini_set("auth_username", "your_mail#example.com");
ini_set("auth_password", "pwd_of_your_mail");
// For the fields $sender / $copy / $receiver, comma separated if there are multiple addresses
$sender = 'your_mail#example.com';
$receiver = 'receiver_mail#example.com';
$object = 'test msg';
$headers = 'MIME-Version: 1.0' . "\n"; // Version MIME
$headers .= 'Content-type: text/html; charset=ISO-8859-1'."\n"; // the Content-type head for the HTML format
$headers .= 'Reply-To: '.$sender."\n"; // Mail reply
$headers .= 'From: "name_of_sender"<'.$sender.'>'."\n";
$headers .= 'Delivered-to: '.$receiver."\n";
$message = 'Hello from Aotoki !';
if (mail($receiver, $object, $message, $headers)) // Send message
{
echo 'Your message has been sent ';
}
else // error
{
echo "Your message could not be sent";
}
?>

Related

JS form submit wont sent success message if mail sent or not

Hi all i am trying to send mails without having the page reload, form validation etc all seems to work ok but i cannot find out if mail is being sent or not as not success message is being printed
here is my html, js and php code
The html
<form name="ContactForm" method="post" action="">
<div class="message_box" style="margin:10px 0px;"></div>
<input type="text" name="name" id="name" placeholder="Name:" />
<input type="email" name="email" id="email" placeholder="Email:" />
<input type="tel" name="phone" id="phone" placeholder="Phone:" />
<textarea name="message" id="message" placeholder="Message:" /></textarea>
<input type="submit" name="send" class="btn btn-default" value="Send message">
</form>
the js
$(document).ready(function() {
var delay = 2000;
$('.btn-default').click(function(e){
e.preventDefault();
var name = $('#name').val();
if(name == ''){
$('.message_box').html(
'<span style="color:red;">Enter Your Name!</span>'
);
$('#name').focus();
return false;
}
var email = $('#email').val();
if(email == ''){
$('.message_box').html(
'<span style="color:red;">Enter Email Address!</span>'
);
$('#email').focus();
return false;
}
if( $("#email").val()!='' ){
if( !isValidEmailAddress( $("#email").val() ) ){
$('.message_box').html(
'<span style="color:red;">Provided email address is incorrect!</span>'
);
$('#email').focus();
return false;
}
}
var phone = $('#phone').val();
if(phone == ''){
$('.message_box').html(
'<span style="color:red;">Enter Your Phone With Country Code!</span>'
);
$('#phone').focus();
return false;
}
var message = $('#message').val();
if(message == ''){
$('.message_box').html(
'<span style="color:red;">Enter Your Message Here!</span>'
);
$('#message').focus();
return false;
}
$.ajax
({
type: "POST",
url: "quickmail.php",
data: "name="+name+"&email="+email+"&phone="+phone+"&message="+message,
beforeSend: function() {
$('.message_box').html(
'<img src="images/loading.gif" width="25" height="25"/>'
);
},
success: function(data)
{
setTimeout(function() {
$('.message_box').html(data);
}, delay);
}
});
});
});
And lastly the php code
if(isset($_POST['name']) !="" && isset($_POST['email']) !=""){
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = "email#yourdomain.com";
$subject = "New Query";
$message = "<p>New email is received from $name.</p>
<p>$message</p>";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= "From: <".$email.">" . "\r\n";
$sent = mail($to,$subject,$message,$headers);
if($sent){
echo "<span style='color:green; font-weight:bold;'>
Thank you for contacting us, we will get back to you shortly.
</span>";
echo '<script type="text/javascript">alert("Thanks $name, we have received your message.")</script>';
}else{
echo "<span style='color:red; font-weight:bold;'>
Sorry! Your form submission is failed.
</span>";
}
}
Would really appreciate it one of you pros could help me fix it.
Thanks a ton in advance
UPDATE
As suggested i tried json but still nothing is being printed?
header('Content-Type: application/json');
$json = json_encode($data);
if(isset($_POST['name']) !="" && isset($_POST['email']) !=""){
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = "email#yourdomain.com";
$subject = "New Query";
$message = "<p>New email is received from $name.</p>
<p>$message</p>";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= "From: <".$email.">" . "\r\n";
$sent = mail($to,$subject,$message,$headers);
if($sent){
$data = "<span style='color:green; font-weight:bold;'>
Thank you for contacting us, we will get back to you shortly.
</span>";
}else{
$data = "<span style='color:red; font-weight:bold;'>
Sorry! Your form submission is failed.
</span>";
}
}
echo $json;

Sending json to php server using jquery ajax - json error

I have problem with my form on my webpage. I am trying to use ajax and json to send the form values to php server, but I can't make properly json object.
My JS code
function sendJsonOpenPopout () {
$('.submitBtn').click(function(e){
e.preventDefault();
var subject = $('.subject').val();
var email = $('.email').val();
var message = $('.message').val();
var dataObject = {
subject: subject,
email: email,
message: message
}
$.ajax({
type: 'POST',
url: '../../kontakt.php',
contentType: "application/json",
dataType: 'json',
data: dataObject,
success: function(data){
alert('Items added');
},
error: function(){
console.log('You have fail');
}
//success: function(){
//var createdDiv = '<div class="divToBeCentered"><p class="dataText">Wiadomość została wysłana pomyślnie.\brDziękuję za kontakt.</p></div>';
//$('body').append(createdDiv);
//}
});
});
My PHP code
<?php
$str_json = file_get_contents('php://input'); //($_POST doesn't work here)
$response = json_decode($str_json, true); // decoding received JSON to array
$subject = $response[0];
$from = $response[1];
$message = $response[2];
$to = "lubycha#gmail.com";
$subject = $_POST['subject'];
$from = $_POST['email'];
$message = $_POST['message'];
$headers = "Content-Type: text/html; charset=UTF-8";
mail($to,$subject,$message,$headers);
?>
I know there is similar question already asked, but the answers didn't help me.
Thanks for helping.
I was able to get the json object and parse it on php side. Some variable might be named different, partly because some of it is pre-written code. Here are the steps I took.
Folder Structure
js/script.js
php/get_data.php
index.html
Index.html
a basic form.
<div id="feedback_panel" class="panel panel-default">
<form id="feedbackform" name="feedbackform" method="post">
<div class="form-group" id="email_wrapper" data-toggle="popover" data-container="body" data-placement="right">
<label class="control-label" for="email">E-mail:</label>
<input type="email" class="form-control" id="email" name="email" placeholder="email#example.com" required>
<span class="help-block"> </span>
</div>
<div class="form-group" id="subject_wrapper" data-toggle="popover" data-container="body" data-placement="right">
<label class="control-label" for="subject">Subject:</label>
<input type="text" class="form-control" id="subject" name="subject" placeholder="Subject" required>
<span class="help-block"> </span>
</div>
<div class="form-group" id="description_wrapper" data-toggle="popover" data-container="body" data-placement="right">
<label class="control-label" for="message">message:</label>
<textarea type="text" class="form-control" id="message" name="message" placeholder="message." required></textarea>
<span class="help-block"> </span>
</div>
<button type="submit" id="feedback_submit" class="btn btn-success">Submit</button>
</form>
</div>
script.js
upon submit, gather data and set it to an object and send to php via ajax.
$(function() {
// process the form
$('#feedbackform').submit(function(event) {
// get the form data - obj that will POSTED to get_data.php
var formData = {
'email' : $('#email').val(),
'subject' : $('#subject').val(),
'message' : $('#message').val()
};
// process the forum
$.ajax({
type : 'POST', // define the type of HTTP verb we want to use (POST for our form)
url : 'php/get_data.php', // the url where we want to POST
data : formData, // our data object
dataType : 'json', // what type of data do we expect back from the server
encode : true
})
// using the done promise callback
.done(function(data) {
// log data to the console so we can see
if ( ! data.success) {
console.log(data);
} else {
console.log(data);
}
});
// stop the form from submitting the normal way and refreshing the page
event.preventDefault();
});
});
get_data.php
receives the data from script.js, do some validations, and then send and an e-mail.
<?php
$errors = array(); // array to hold validation errors
$data = array(); // array to pass back data
// validate the variables ======================================================
// if any of these variables don't exist, add an error to our $errors array
$email;
$subject;
$message;
//check to see if the data exist, else write an error message,
function check_data(){
$user_inputs = array();
if (empty($_POST['email'])){
$errors['email'] = 'Email is required.';
return false;
}else{
$email = $_POST['email'];
array_push($user_inputs,$email);
}
if (empty($_POST['subject'])){
$errors['subject'] = 'subject is required.';
return false;
}else{
$subject = $_POST['subject'];
array_push($user_inputs,$subject);
}
if (empty($_POST['message'])){
$errors['message'] = 'message is required.';
return false;
}else{
$message = $_POST['message'];
array_push($user_inputs,$message);
}
return $user_inputs;
}
//getting array of data from check_data
$verify_data = check_data();
// return a response ===========================================================
// if there are any errors in our errors array, return a success boolean of false
if ( ! empty($errors)) {
// if there are items in our errors array, return those errors
$data['success'] = false;
$data['errors'] = $errors;
echo json_encode($data);
} else {
// show a message of success and provide a true success variable
$data['success'] = $verify_data;
$data['message'] = 'Success!';
//if everything is good, sent an email.
if($verify_data != false){
send_email($verify_data);
}
}
function send_email($info_data){
// person who it going
$to = 'Email, Some <some_email#mailinator.com>';
//subject of the email
$subject = $info_data[1];
$result = str_replace(' ', ' ', $info_data[2]);
$result = nl2br($result);
$result = wordwrap($result, 70, "\r\n");
//body of the email.
$message = "<html><body>";
$message .= "<p style = 'width: 400px;'>" . $result . "</p>";
$message .= "<br/>";
$message .= "</body></html>";
$headers = "From: Email, Some <some_email#mailinator.com>" . "\r\n" . 'Reply-To: '. $info_data[0] . "\r\n" ."X-Mailer: PHP/" . phpversion();
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8";
//sent mail: check to see if it was sent.
if(mail($to, $subject, $message, $headers)){
$data["went"] = "went";
$data['message'] = 'Success!';
}else{
$data["went"] = "didn't go";
$data['message'] = 'Sorry!';
}
// echo the log
echo json_encode($data);
}
?>
lot to cover, let me know if you any questions. I'll be happy to answer.

Not receiving all fields in php mail

Here is the mail handler only part being received in sent emails is the actual message missing parts are name and phone.
<?php
session_start();
$email_to = "test#test.com";
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$headers = "From: $email\r\n";
$headers .= "Reply-To: $email\r\n";
if(mail($email_to, $subject, $message, $headers)){
echo "success";
}
else{
echo "failed";
}
?>
Here is the html part which I have checked over and over and cant figure out whats wrong
<form id="contact" class="row" name="form1" method="post" action="">
<div class="span2">
<label>Name <span class="req">*</span></label>
<input type="text" class="full" name="name" id="name"/>
<div id="error_name" class="error">Please check your name</div>
</div>
<div class="span2">
<label>Phone <span class="req">*</span></label>
<input type="text" class="full" name="phone" id="phone"/>
<div id="error_phone" class="error">Please check your phone</div>
</div>
<div class="span4">
<label>Email <span class="req">*</span></label>
<input type="text" class="full" name="email" id="email"/>
<div id="error_email" class="error">Please check your email</div>
</div>
<div class="span8">
<label>Message <span class="req">*</span></label>
<textarea cols="8" rows="10" name="message" id="message" class="full"></textarea>
<div id="error_message" class="error">Please check your message</div>
<div id="mail_success" class="success"> Thank you. Your message has been sent.</div>
<div id="mail_failed" class="error">Error, email not sent</div>
<p id="btnsubmit"><input type="submit" id="send" value="Send" class="btn btn-large"/></p>
</div>
</form>
Js script -------------------
$(document).ready(function(){
$("#send").click(function(){
var name = $("#name").val();
var phone = $("#phone").val();
var email = $("#email").val();
var message = $("#message").val();
var error = false;
if (name.length == 0) {
var error = true;
$("#error_name").fadeIn(500);
}
else {
$("#error_name").fadeOut(500);
}
if (phone.length == 0) {
var error = true;
$("#error_phone").fadeIn(500);
}
else {
$("#error_phone").fadeOut(500);
}
if(email.length == 0 || email.indexOf("#") == "-1" || email.indexOf(".") == "-1"){
var error = true;
$("#error_email").fadeIn(500);
}
else {
$("#error_email").fadeOut(500);
}
if(message.length == 0){
var error = true;
$("#error_message").fadeIn(500);
}else{
$("#error_message").fadeOut(500);
}
if(error == false){
$("#send").attr({"disabled" : "true", "value" : "Loading..." });
$.ajax({
type: "POST",
url : "send.php",
data: "name=" + name + "&email=" + email + "&subject=" + "Website Enquiry" + "&message=" + message,
success: function(data){
if(data == 'success'){
$("#btnsubmit").remove();
$("#mail_success").fadeIn(500);
}else{
$("#mail_failed").html(data).fadeIn(500);
$("#send").removeAttr("disabled").attr("value", "send");
}
}
});
}
return false;
});
});
Obviously, you are missing parts!... You simply declare variables, but you didn't include them in the mail itself.
In this example, I'm adding $name and $phone to $message body.
<?php
session_start();
$email_to = "test#test.com";
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'] . "\n";
$message .= "Name: " . $name . "\n";
$message .= "Phone: " . $phone;
$headers = "From: $email\r\n";
$headers .= "Reply-To: $email\r\n";
if(mail($email_to, $subject, $message, $headers)){
echo "success";
}
else{
echo "failed";
}
?>

PHP mail() sends 2 copies

I have this problem with my contact form. When I submit the form I receive 2 identical emails in my box.
Im using JS to check the form for errors and then simple PHP mail() function to send the email.
Here is the PHP code:
<?php
$from = Trim(stripslashes($_POST['email']));
$to = "myemail#gmail.com";
$subject = "Contact Form";
$name = Trim(stripslashes($_POST['name']));
$email = Trim(stripslashes($_POST['email']));
$number = Trim(stripslashes($_POST['number']));
$message = Trim(stripslashes($_POST['message']));
$body = "";
$body .= "Name: ";
$body .= $name;
$body .= "\n\n";
$body .= "E-mail: ";
$body .= $email;
$body .= "\n\n";
$body .= "Telephone Number: ";
$body .= $number;
$body .= "\n\n";
$body .= "Message: ";
$body .= $message;
$body .= "\n\n";
$success = mail($to, $subject, $body, "From: <$from>" . "\r\n" . "Reply-to: <$from>" . "\r\n" . "Content-type: text; charset=utf-8");
?>
And here is the JS:
$(".submit").click(function() {
var name = $("input[name=name]").val();
var email = $("input[name=email]").val();
var number = $("input[name=number]").val();
var message = $("textarea[name=message]").val();
if (defaults['name'] == name || name == "") {
$(".error").text("Please enter your name!");
return false;
} else if (defaults['email'] == email || email == "") {
$(".error").text("Please enter your email!");
return false;
} else if (defaults['number'] == number || number == "") {
$(".error").text("Please enter your number!");
return false;
} else if (defaults['message'] == message || message == "") {
$(".error").text("Plese enter your message!");
return false;
}
var dataString = 'name=' + name + '&email=' + email + '&number=' + number + '&message=' + message;
$(".error").text("Please wait...").hide().fadeIn("fast");
$.ajax({
type: "POST",
url: "contact.php",
data: dataString,
success: function() {
$('#form form').html("");
$('#form form').append("<div id='success'>Your message has been sent! Thank you</div>");
}
});
return false;
});
And here is the HTML form:
<form id="contact" method="post" action="#">
<label for="name">Name:</label>
<input type="text" name="name" required tabindex="1">
<label for="email">Email adress:</label>
<input type="text" name="email" required tabindex="2">
<label for="number">Tel. number:</label>
<input type="text" name="number" tabindex="3">
<label for="message">Your message:</label>
<textarea name="message" rows="10" cols="70" required tabindex="4"></textarea>
<input type="checkbox" id="terms" name="terms" value="terms">I agree to the terms
<input type="submit" name="submit" class="submit more-info" tabindex="5" value="Send">
<span class="error"></span>
</form>
I have been using the same code for all of my contact forms and it worked all right. Could it be hosting/server related issue?
replace your click event
$(".submit").click(function() {
with
$('.submit').unbind('click').click(function() {
code.
What I can assume your click event is binding two times may be due to a lot of the mess in the code
also use this line in the end of the click event function
$('.submit').unbind('click').click(function() {
// your stuff
event.stopImmediatePropagation(); // as long as not bubbling up the DOM is ok?
});
for reference have a look at the link: https://forum.jquery.com/topic/jquery-executes-twice-after-ajax
$(".submit").click(function(e) { ... }) POSTS to your server for the first time.
Because this is a <submit> button, the form will still submit. The form POSTS to your server for the second time.
The solution would be adding a e.preventDefault() at the bottom inside the $(".submit").click function...
$(".submit").click(function(e) {
// ^ add this e
var name = ...;
$.ajax({
...
});
e.preventDefault();
return false;
});
Try removing the jQuery animations:
$(".error").text("Please wait...").hide().fadeIn("fast");
They can sometimes cause problems.

Validation does not work with PHP

I am having problem to see the problem with a pre-scripted template.
There are 3 files as follows,
/contact.php
/forms/contact.php
/js/forms.js
So when a visitor fills up the contact.php in root directory it redirects to /forms/contact.php and forms.js checks the form and if there is no problem sends an email.
Here is my /contact.php which includes the form,
<form id="contactform" method="post" action="forms/contact.php">
<div class="divide10"></div>
<input id="name" name="name" value="Your Name" type="text" class="prepared-input">
<div class="divide15"></div>
<input id="email" name="email" value="Your Email" type="text" class="prepared-input">
<div class="divide15"></div>
<textarea id="contactmessage" name="message" rows="3" class="prepared-input">Your Message</textarea>
<div class="divide15"></div>
<input type="submit" id="From_Comment_Go" value="Send Message " class="btn maincolor small">
<span class="errormessage hiddenatstart">Error! Please correct marked fields.</span>
<span class="successmessage hiddenatstart">Message send successfully!</span>
<span class="sendingmessage hiddenatstart">Sending...</span>
</form>
Here is my /forms/contact.php
<?php
$to = 'example#mail.com';
//Language Options
$contact_labelmailhead = 'Contact Form Email';
$contact_labelmailsubject = 'Contact Form Email from';
$contact_labelname = 'Name';
$contact_labelemail = 'Email';
$contact_labelmessage = 'Message';
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$message = str_replace(chr(10), "<br>", $_POST['message']);
$body = "<html><head><title>$contact_labelmailhead</title></head><body><br>";
$body .= "$contact_labelname: <b>" . $name . "</b><br>";
$body .= "$contact_labelemail <b>" . $email . "</b><br>";
$body .= "$contact_labelmessage:<br><hr><br><b>" . $message . "</b><br>";
$body .= "<br></body></html>";
$subject = $contact_labelmailsubject.' ' . $name;
$header = "From: $email\n" . "MIME-Version: 1.0\n" . "Content-type: text/html; charset=utf-8\n";
mail($to, $subject, $body, $header);
?>
and lastly forms.js is here,
jQuery(document).ready(function() {
/* Contact Form */
if(jQuery('#contactform').length != 0){
addForm('#contactform');
}
/* Quick Contact */
if(jQuery('#quickcontact').length != 0){
addForm('#quickcontact');
}
/* Blog Comments */
if(jQuery('#replyform').length != 0){
addForm('#replyform');
}
});
function addForm(formtype) {
var formid = jQuery(formtype);
var emailsend = false;
formid.find("input[type=submit]").click(sendemail);
function validator() {
var emailcheck = /^([\w-]+(?:\.[\w-]+)*)#((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
var othercheck = /.{4}/;
var noerror = true;
formid.find(".requiredfield").each(function () {
var fieldname = jQuery(this).attr('name');
var value = jQuery(this).val();
if(value == "Name *" || value == "Email *" || value == "Message *"){
value = "";
}
if(fieldname == "email"){
if (!emailcheck.test(value)) {
jQuery(this).addClass("formerror");
noerror = false;
} else {
jQuery(this).removeClass("formerror");
}
}else{
if (!othercheck.test(value)) {
jQuery(this).addClass("formerror");
noerror = false;
} else {
jQuery(this).removeClass("formerror");
}
}
})
if(!noerror){
formid.find(".errormessage").fadeIn();
}
return noerror;
}
function resetform() {
formid.find("input").each(function () {
if(!jQuery(this).hasClass("button")) jQuery(this).val("");
})
formid.find("textarea").val("");
emailsend = false;
}
function sendemail() {
formid.find(".successmessage").hide();
var phpfile = "";
if(formtype=="#contactform"){
phpfile = "forms/contact.php";
}else if(formtype.lastIndexOf("c_")){
phpfile = "forms/quickcontact.php";
}else{
phpfile = "";
}
if (validator()) {
if(!emailsend){
emailsend = true;
formid.find(".errormessage").hide();
formid.find(".sendingmessage").show();
jQuery.post(phpfile, formid.serialize(), function() {
formid.find(".sendingmessage").hide();
formid.find(".successmessage").fadeIn();
if(!formtype.lastIndexOf("c_"))resetform();
});
}
}
return false
}
}
So, leaving the form sends Values :S and does not check anything. Shall I try to fix this or try to implement something else? I am not that into jQuery and cannot say if there is something wrong with validation script.
Some advice would be great!
Thank you!
There are errors on .js syntax, this could stop some js code from being called. First of all, fix these errors in js like this:
formid.find("input").each(function ()
{
if(!jQuery(this).hasClass("button")) jQuery(this).val("");
})//this is missing a ;
After that you can think properly on post method like Kevin Schmid said..
The validator function check each input with ".requiredfield" class.
Sample Code :
formid.find(".requiredfield").each(function () {

Categories