$(document).ready(function() {
$('#contact_form').bootstrapValidator({
// To use feedback icons, ensure that you use Bootstrap v3.1.0 or later
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
first_name: {
validators: {
stringLength: {
min: 2,
},
notEmpty: {
message: 'Please supply your first name'
}
}
},
last_name: {
validators: {
stringLength: {
min: 2,
},
notEmpty: {
message: 'Please supply your last name'
}
}
},
email: {
validators: {
notEmpty: {
message: 'Please supply your email address'
},
emailAddress: {
message: 'Please supply a valid email address'
}
}
},
phone: {
validators: {
notEmpty: {
message: 'Please supply your phone number'
},
phone: {
country: 'US',
message: 'Please supply a vaild phone number with area code'
}
}
},
address: {
validators: {
stringLength: {
min: 8,
},
notEmpty: {
message: 'Please supply your street address'
}
}
},
city: {
validators: {
stringLength: {
min: 4,
},
notEmpty: {
message: 'Please supply your city'
}
}
},
state: {
validators: {
notEmpty: {
message: 'Please select your state'
}
}
},
zip: {
validators: {
notEmpty: {
message: 'Please supply your zip code'
},
zipCode: {
country: 'US',
message: 'Please supply a vaild zip code'
}
}
},
comment: {
validators: {
stringLength: {
min: 10,
max: 200,
message:'Please enter at least 10 characters and no more than 200'
},
notEmpty: {
message: 'Please supply a description of your project'
}
}
}
}
})
.on('success.form.bv', function(e) {
$('#success_message').slideDown({ opacity: "show" }, "slow") // Do something ...
$('#contact_form').data('bootstrapValidator').resetForm();
// Prevent form submission
e.preventDefault();
// Get the form instance
var $form = $(e.target);
// Get the BootstrapValidator instance
var bv = $form.data('bootstrapValidator');
// Use Ajax to submit form data
$.post($form.attr('action'), $form.serialize(), function(result) {
console.log(result);
}, 'json');
});
});
<?php require_once('recaptchalib.php'); $privatekey = "My Key"; $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
if (!$resp->is_valid) { // What happens when the CAPTCHA was entered incorrectly die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." . "(reCAPTCHA said: " . $resp->error . ")"); } else { //--------------------------Set these paramaters--------------------------
// Subject of email sent to you.$subject = ' Quote Form Response';
// Your email address. This is where the form information will be sent.$emailadd = 'myemail';
// From email address. This is who the form information will be sent from.$email_from = $_POST['email'];
// Where to redirect after form is processed.$url = 'javascript://history.go(-1)';
// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.$req = '0';
// --------------------------Do not edit below this line--------------------------$text = "Results from Quote form:\n\n";$space = ' ';$line = '';foreach ($_POST as $key => $value){if ($req == '1'){if ($value == ''){echo "$key is empty";die;}}$j = strlen($key);if ($j >= 20){echo "Name of form element $key cannot be longer than 20 characters";die;}$j = 20 - $j;for ($i = 1; $i <= $j; $i++){$space .= ' ';}$value = str_replace('\n', "$line", $value);$conc = "{$key}:$space{$value}$line";$text .= $conc;$space = ' ';}mail($emailadd, $subject, $text, 'From: '.$email_from.'');echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">'; ?>