I'm having a problem on how to add an attachment in my working form, i'm using Bootstrap, JQuery and PHP. i have no idea on how to add an attachment where the user will attach their Resume's and then send it to email.
i hope you can help me with this without changing my entire code. is it even possible?.
This is my initial input form
<section class = "resume section-padding" id = "resume "><div class="form-group col-md-6">
<label for="fName">First Name</label>
<input type="text" class="form-control" id="fName" placeholder="First Name">
</div>
<div class="form-group col-md-6">
<label for="lName">Last Name</label>
<input type="text" class="form-control" id="lName" placeholder="Last Name">
</div>
<div class = "form-group col-md-12">
<label for="address">Address</label>
<input type="text" class="form-control" id="address" placeholder="Address">
</div>
<div class = "form-group col-md-4">
<label for="doBirth">Date of Birth</label>
<input type="date" class="form-control" id="doBirth" placeholder="Date of Birth">
</div>
<div class = "form-group col-md-4">
<label for="city">City</label>
<input type="text" class="form-control" id="city" placeholder="City">
</div>
<div class = "form-group col-md-4">
<label for="zipCode">ZIP CODE</label>
<input type="number" class="form-control" id="zipCode" placeholder="ZIP">
</div>
<div class = "form-group col-md-6">
<label for="email">E-mail</label>
<input type="email" class="form-control" id="email" placeholder="Email">
</div>
<div class = "form-group col-md-6">
<label for="phone">Phone</label>
<input type="number" class="form-control" id="phone" placeholder="Phone Number">
</div>
</div>
This is my jquery it will get the value of the form.
$('.resume #getResume').on('click', function(e){
e.preventDefault();
var fName = $('#fName').val();
var lName = $('#lName').val();
var address = $('#address').val();
var doBirth = $('#doBirth').val();
var city = $('#city').val();
var zipCode = $('#zipCode').val();
var email = $('#email').val();
var phone = $('#phone').val();
var form = new Array({ 'fName':fName, 'lName':lName, 'address':address, 'doBirth':doBirth, 'city':city, 'zipCode':zipCode,
'email':email, 'phone':phone });
$.ajax({
type: 'POST',
url: "/path/to/url.php",
data: ({'action': 'resume', 'form': form})
}).done(function(data) {
$('#resume .result').html(data);
$(".resume")[0].reset();
});
});
This is my php this where my jQuery will pass the value
$sendTo = "email#email.com";
$action = $_POST['action'];
$name = $_POST['form'][0]['name'];
$email = $_POST['form'][0]['email'];
$subject = $_POST['form'][0]['subject'];
$message = $_POST['form'][0]['message'];
if ($name == "" || $email == "" || $message == "" || $subject == "") {
echo "<p class=\"error\">There was problem while sending E-Mail. Please verify entered data and try again!</p>";
exit();
}
else
{
$header = 'From: ' . $name . '<' . $email . ">\r\n" .
'Reply-To: ' . $email . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$sent = mail($sendTo, $subject, $message, $header);
if ($sent) {
echo "<p class=\"success\">Message sent succesfully.</p>";
} else {
echo "<p class=\"error\">There was problem while sending E-Mail.</p>";
}
}
?>
If you are not using any framework and in core php it is very easy to upload a file. You can see all the code and working here for better understanding. This is good source to get thing done.
In your current code just add a field to upload a file. Like this
<input type="file" name="fileToUpload" id="fileToUpload">
. Also dont forget to ON the file_uploads in php.ini file.
To add it in the email:
for adding in the email just catch the file in the script file and send it to the email like this.
$email->AddAttachment( $file_to_attach , 'NameOfFile.pdf' );
Related
I need to send the mail in wordpress for the custom ajax form. The mail
should contain full name, email, phone number and the
message(comment). Please help me to do it.
I have included the html code as a shortcode in functions.php .
function send_grivence(){
var form1 = jQuery("#myform").serialize();
console.log(form1);
jQuery.ajax({
data: {action: 'send_form', form:form1},
type: 'post',
url: 'mydomain.com/wp-admin/admin-ajax.php/',
success: function(data) {
console.log(data); //should print out the name since you sent it along
}
});
}
<form class="form-horizontal" id="myform">
<fieldset>
<div class="control-group">
<!-- Username -->
<label class="control-label" for="fullname">Fullname:</label>
<div class="controls">
<input type="text" id="fullname" name="fullname" placeholder="your-name" class="input-xlarge">
</div>
</div>
<div class="control-group">
<!-- Password-->
<label class="control-label" for="email">Email Id:</label>
<div class="controls">
<input type="email" id="email" name="email" placeholder="your-email" class="input-xlarge">
</div>
</div>
<div class="control-group">
<!-- Password-->
<label class="control-label" for="number">Phone No:</label>
<div class="controls">
<input type="text" id="phonenumber" name="phonenumber" placeholder="your-phone no" class="input-xlarge">
</div>
</div>
<div class="control-group">
<!-- Password-->
<label class="control-label" for="number">Comment:</label>
<div class="controls">
<textarea name="name" rows="8" cols="80" placeholder="your-message"></textarea>
</div>
</div>
<div class="control-group">
<!-- Button -->
<div class="controls">
<a onclick="send_form()" class="btn btn-success">Submit</a>
</div>
</div>
</fieldset>
</form>
first jquery code to submit form via ajax
jQuery(document).ready(function (jQuery) {
jQuery('#myform').submit(contactSubmit);
function contactSubmit() {
var contactForm = jQuery('#myform').serialize();
jQuery.ajax({
type: "POST",
url: "/wp-admin/admin-ajax.php",
data: contactForm,
success: function (data) {
// console.log(id);
console.log(data);
}
});
return false;
}
});
make sure that you place a action input in your form like this
<input type="hidden" name="action" value="contactForm"/>, just paste it before submit button. Note that contactForm function is called in function.php
then place a function in your function.php
function contactForm() {
$name = $_POST['fullname'];
$email = $_POST['email'];
$phone = $_POST['phonenumber'];
$message = $_POST['comment'];
$quote = 'Full Name: ' . $name . "\n\r" . 'Email: ' . $email . "\n\r" . 'Phone: ' . $phone . "\n\r" . 'Message: ' . $message . "\n\r";
$to = "YOUR EMAIL ADDRESS"; // put your email here
$headers = 'From:' . $name . '<' . $email . '>' . "\r\n"; // put user's email here or duplicate your email
$subject = 'Contact Form';
if ( wp_mail( $to, $subject, $quote, $headers ) === false ) {
echo "Error";
} else {
echo "<h3> Mail Sent Successfully Done</h3>";
}
die();
}
add_action( 'wp_ajax_contactForm', 'contactForm' );
add_action( 'wp_ajax_nopriv_contactForm', 'contactForm' );
Also make sure you replace your email in "YOUR EMAIL ADDRESS". also, make sure your url: "/wp-admin/admin-ajax.php", displays your full address. In local you might include url: "/YOUR_FOLDER_HERE/wp-admin/admin-ajax.php", else in live server it works fine.
EDIT
<textarea name="name" rows="8" cols="80" placeholder="your-message"></textarea>
change name="name" to name="comment"
Hope this helps.
I have form which contains multiple checkboxes and i need to send their values to the email but i am unable to send it through the ajax to email script.
But without ajax php code is working please suggest where i am missing something
Below is my html code
<form enctype="multipart/form-data">
<div class="col-md-12 col-sm-12"><input type="text" id="name" name="name" placeholder="Name:*" class="form-control" required/></div>
<div class="col-md-12 col-sm-12"><input type="email" id="email" name="email" placeholder="Email:*" class="form-control" required/></div>
<div class="col-md-12 col-sm-12"><input type="text" id="phone" name="phone" placeholder="Phone:*" class="form-control" required/></div>
<p>Vehicle Type You're Shipping?:*</p>
<div class="input-holder field-checkbox">
<div class="field-element ">
<input type="checkbox" id="" name="checkbox[]" value="Car, Truck Or SUV" class="required ">
<label for="1dfb36b53196072fe797a082d9892947-3-0">Car, Truck Or SUV</label>
</div>
<div class="field-element ">
<input type="checkbox" id="" name="checkbox[]" value="Motorcycle Or ATV" class="required ">
<label for="1dfb36b53196072fe797a082d9892947-3-1">Motorcycle Or ATV</label>
</div>
<div class="field-element ">
<input type="checkbox" id="" name="checkbox[]" value="RV Or Motorhome" class="required ">
<label for="1dfb36b53196072fe797a082d9892947-3-2">RV Or Motorhome</label>
</div>
<div class="field-element ">
<input type="checkbox" id="" name="checkbox[]" value="Boat/Yacht, Jet Ski" class="required ">
<label for="1dfb36b53196072fe797a082d9892947-3-3">Boat/Yacht, Jet Ski</label>
</div>
<div class="field-element ">
<input type="checkbox" id="" name="checkbox[]" value="Trailer" class="required ">
<label for="1dfb36b53196072fe797a082d9892947-3-4">Trailer</label>
</div>
<div class="field-element ">
<input type="checkbox" id="" name="checkbox[]" value="Other" class="required ">
<label for="1dfb36b53196072fe797a082d9892947-3-5">Other</label>
</div>
SEND
<center> <div class="result" id="result"style="color:red;font-weight: 900;background: #fff; "></div></center>
</form>
and i have this code for ajax
<script>
function submit_user(){
var name = document.getElementById('name').value;
var email = document.getElementById('email').value;
var phone = document.getElementById('phone').value;
var country = document.getElementById('country').value;
var current = document.getElementById('current').value;
var model = document.getElementById('model').value;
var enquiry = document.getElementById('enquiry').value;
var myCheckboxes = new Array();
$("input:checkebox").each(function() {
data['myCheckboxes[]'].push($(this).val());
});
$.ajax({
type: "POST",
url: "script.php?name="+name+"&email="+email+"&phone="+phone+"&checkbox="+myCheckboxes+"&country="+country+"¤t="+current+"&model="+model+"&enquiry="+enquiry,
success:function(data) {
$( ".result" ).html(data);
}
});
// alert("2s");
}
and i have this script for php
<?php
if (!empty($_GET['name']) && !empty($_GET['email']) && !empty($_GET['phone'] ) && !empty($_GET['country']) && !empty($_GET['current']) && !empty($_GET['model'])) {
$message = "New Email from landing Page";
$name = $_GET['name'];
$email = $_GET['email'];
$phone = $_GET['phone'];
$country =$_GET['country'];
$current =$_GET['current'];
$model =$_GET['model'];
$enquiry =$_GET['enquiry'];
$from = "From: Booking from Landing Page";
$to = "email#gmail.com";
$subject = " You Got a Booking From Landing Page!";
if (isset($_GET['myCheckboxes']) && !empty($_GET['myCheckboxes'])) {
foreach($_GET['myCheckboxes'] as $selected ){
$MESSAGE_BODY .= $selected."\r\n";
}
}
$mail = "
Info: ".$message."
Name: ".$name."
email: ".$email."
Phone: ".$phone."
checkbox ".$MESSAGE_BODY."
Country: ".$country."
Currrent: ".$current."
Model: ".$model."
Message: ".$enquiry."";
mail($to, $subject, $mail, $from);
//readfile("thank-you.html");
//exit;
echo "Thank You, I will get back to you ASAP";
}else{
//readfile("error.html");}
echo "something is incorrect, please retry";
}
?>
Try changing -
var myCheckboxes = new Array();
$("input:checkebox").each(function() {
data['myCheckboxes[]'].push($(this).val());
});
to
var myCheckboxes = new Array();
$("input:checkbox:checked").each(function() {
myCheckboxes.push($(this).val());
});
(1) input:checkebox should be input:checkbox
(2) added :checked as you only want to send checked checkboxes, not each one
(3) you want to .push() to myCheckboxes, not to data['myCheckboxes[]']
I have a questionnaire form on my website that emails me answers submitted by visitors. One of the questions asks users for the best contact time (morning, afternoon, evening) The name of that select class is contact-time.
Currently in the body of the email, it's displayed as Contact-time just like I named it in the html form. I want it to display as Contact Time.
How can I build the body of the email so that it displays contact-time as Contact Time while still being able to fetch the value from select class named contact-time? I've looked through pretty much all questions regarding this and couldn't find any relevant information.
PHP code that builds the email and then sends it
<?php
function constructEmailBody () {
$fields = array("name" => true, "email" => true, "address" => true, "phone" => true, "contact-time" => true);
$message_body = "";
foreach ($fields as $name => $required) {
$postedValue = $_POST[$name];
if ($required && empty($postedValue)) {
errorResponse("$name is empty.");
} else {
$message_body .= ucfirst($name) . ": " . $postedValue . "\n";
}
}
return $message_body;
}
//attempt to send email
$emailBody = constructEmailBody();
require './vender/php_mailer/PHPMailerAutoload.php';
$email = new PHPMailer;
$email->CharSet = 'UTF-8';
$email->isSMTP();
$email->Host = 'smtp.gmail.com';
$email->SMTPAuth = true;
$email->Username = 'email#domain.com';
$email->Password = 'MyPassword';
$email->SMTPSecure = 'tls';
$email->Port = 587;
$email->setFrom($_POST['email'], $_POST['name']);
$email->addAddress('email#domain.com');
$email->Subject = 'Estimate Request Answers';
$email->Body = $emailBody;
//try to send the message
if($email->send()) {
echo json_encode(array('message' => 'Thank you! Your message was successfully submitted.'));
} else {
errorResponse('An unexpected error occured while attempting to send the email: ' . $email->ErrorInfo);
}
?>
HTML form
<form role="form" id="estimateForm" method="POST">
<div class="col-xs-12 contact-information">
<div class="form-group">
<fieldset>
<legend>Contact Information</legend>
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
<label class="control-label" for="name">Name</label>
<input type="text" class="form-control" id="name" name="name" placeholder="Enter Name">
<label class="control-label" for="email">Email</label>
<input type="email" class="form-control" id="email" name="email" placeholder="Enter Email">
<label class="control-label" for="address">Address</label>
<input type="text" class="form-control" id="address" name="address" placeholder="Enter Address">
</div>
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
<label class="control-label" for="phone">Phone Number</label>
<input type="tel" class="form-control" id="phone" name="phone" placeholder="Enter Phone Number">
<label class="control-label" for="contact-time">Preferred Contact Time</label>
<select class="selectpicker contact-time" id="contact-time" name="contact-time" title="Preferred Contact Time">
<option value="Morning">Morning (9-11am)</option>
<option value="Afternoon">Afternoon (11-2pm)</option>
<option value="Evening">Evening (2-5pm)</option>
</select>
<label class="control-label" for="contact-method">Preferred Contact Method</label>
<select class="selectpicker contact-method" id="contact-method" name="contact-method" title="Preferred Contact Method">
<option>By Phone</option>
<option>By Email</option>
</select>
</div>
</fieldset>
</div>
</div>
</form>
Thank you for your time in advance and I appreciate any help.
nothing to do with the mail code you can use a simple str_replace() on $name
or
if($name =='whatever'){
$name='something else';
}
or about 10 other options
I am building a html5 based contact form with php mail script.
I do not know why i am getting empty emails on submission as well as If i want to print any message like "Thank you for contacting us", How would I do that.
<?php
$name = (isset($_POST['name']) ? $_POST['name'] : null);
$phone = (isset($_POST['phone']) ? $_POST['phone'] : null);
$address = (isset($_POST['address']) ? $_POST['address'] : null);
$appointment_datepicker =(isset($_POST['appointment-datepicker']) ? $_POST['appointment-datepicker'] : null);
$message = (isset($_POST['textarea']) ? $_POST['textarea'] : null);
$email_address = (isset($_POST['email']) ? $_POST['email'] : null);
// Create the email and send the message
$to = 'dipen2512#gmail.com'; // Add your email address inbetween the '' replacing yourname#yourdomain.com - This is where the form will send a message to.
$email_subject = "Website Contact Form: $name";
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nPhone: $phone\n\nEmail: $email_address\n\nAppointment: $appointment_datepicker\n\nAddress: $address\n\nMessage:\n$message";
$headers = "From: noreply#dev-designers.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply#yourdomain.com.
$headers .= "Reply-To: $email_address";
$mail_status = mail($to,$email_subject,$email_body,$headers);
/** Check for empty fields
if(!empty($_POST['name']) || !empty($_POST['phone']) || !empty($_POST['address']) || !empty($_POST['appointment-datepicker']) || !empty($_POST['textarea']) || filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{**/
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
print( "Thank you for the message. We will contact you shortly.");
window.location = 'http://thankyou.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
print( 'Message failed. Please, send an email to gordon#template-help.com');
window.location = 'http://thankyou.html';
</script>
<?php
}
?>
<form id="appointment-form" action="contact_me.php" method="post" class="appointment-form">
<div class="col-md-6">
<div class="form-group form-md-line-input form-md-floating-label">
<input id="name" type="text" class="form-control" required="required">
<label for="name">Name</label>
</div>
<div class="form-group form-md-line-input form-md-floating-label">
<input id="phone" type="text" class="form-control" required="required" pattern="/[1-9][01][0-9]-?[0-9]{3}-=[0-9]{4}">
<label for="phone">Phone Number</label>
</div>
<div class="form-group form-md-line-input form-md-floating-label">
<input id="address" type="text" class="form-control" required="required">
<label for="address">Address </label>
</div>
<div class="form-group form-md-line-input form-md-floating-label">
<input id="appointment-datepicker" type="text" class="form-control form-line-input" required="required">
<label for="appointment-datepicker">Book a date</label>
</div>
</div>
<div class="col-md-6">
<div class="form-group form-md-line-input form-md-floating-label">
<input id="email" type="text" class="form-control" required="required" pattern="[a-zA-Z0-9!#$%&'*+\/=?^_`{|}~.-]+#[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*">
<label for="email">Email Address</label>
</div>
<div class="form-group form-md-line-input form-md-floating-label">
<textarea id="textarea" rows="4" class="form-control form-textarea"></textarea>
<label for="textarea">Message</label>
</div>
<div class="btn-wrapper">
<button type="submit" class="btn btn-make-app">Send to us</button>
</div>
</div>
<div class="clearfix"> </div>
</form>
Your form inputs are missing "name" attributes. IDs don't get passed along in a form request; only the name-value pairings.
v---------v
<input id="name" name="name" type="text" class="form-control" required="required">
Hi I have a contact form using PHP AJAX but filling the form, it is successful but when I try to fillup again the form it is not submitting unless I refresh the page, it will go back to normal again. What will be the problem of this?
Thanks
HTML Code
<form role="form" id="feedbackForm" method="POST">
<div class="col-lg-6">
<div class="form-group">
<label class="control-label" for="textinput">First Name<span class="required">*</span></label>
<input type="text" class="form-control required" id="first_name" name="first_name" placeholder="Enter your First Name"/>
<span class="help-block" style="display: none;">Please enter your first name.</span>
</div>
<div class="form-group">
<label class="control-label" for="textinput">Last Name<span class="required">*</span></label>
<input type="text" class="form-control" id="last_name" name="last_name" placeholder="Enter your Last Name"/>
<span class="help-block" style="display: none;">Please enter your last name.</span>
</div>
<div class="form-group">
<label class="control-label" for="textinput">Email Address<span class="required">*</span></label>
<input type="email" class="form-control" id="email" name="email" placeholder="Enter your email address"/>
<span class="help-block" style="display: none;">Please enter a valid e-mail address.</span>
</div>
<div id="companyname_con" class="form-group">
<label class="control-label" for="textinput">Company Name</label>
<input type="text" class="form-control" id="company_name" name="company_name" placeholder="Enter your company name">
</div>
<div class="form-group">
<label class="control-label" for="textinput">Message<span class="required">*</span></label>
<textarea rows="10" cols="100" class="form-control" id="contact_message" name="contact_message" placeholder="Enter your message"></textarea>
<span class="help-block" style="display: none;">Please enter a message.</span>
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<label for="selectbasic">How did you hear about us?</label>
<select id="selectbasic" name="selectbasic" class="form-control">
<option value="None">Select</option>
<option value="Search Engine">Search engine</option>
<option value="Microsoft DPE">Microsoft DPE</option>
<option value="Microsoft Event">Microsoft event</option>
<option value="Social Media">Social media</option>
<option value="Word of Mouth">Word of mouth</option>
<option value="Other">Other</option>
</select>
</div>
<div class="checkbox">
<label>
<input type="checkbox" id="emailUpdates" name="emailUpdates" value="Yes"> Please keep me informed of kinectAPI product updates and news
</label>
</div>
<img id="captcha" src="library/vender/securimage/securimage_show.php" alt="CAPTCHA Image" />
Show a Different Image<br/>
<div class="form-group" style="margin-top: 10px;">
<input type="text" class="form-control" name="captcha_code" id="captcha_code" placeholder="For security, please enter the code displayed in the box." />
<span class="help-block" style="display: none;">Please enter the code displayed within the image.</span>
</div>
<span class="help-block" style="display: none;">Please enter a the security code.</span>
<button type="submit" id="feedbackSubmit" class="btn btn-purple btn-md message-btn">Submit Message</button>
</div>
</form>
PHP Code
<?php
//start a session -- needed for Securimage Captcha check
session_start();
//add you e-mail address here
define("MY_EMAIL", "dummy#email.com");
/**
* Sets error header and json error message response.
*
* #param String $messsage error message of response
* #return void
*/
function errorResponse ($contact_message) {
header('HTTP/1.1 500 Internal Server Error');
die(json_encode(array('message' => $contact_message)));
}
/**
* Return a formatted message body of the form:
* Name: <name of submitter>
* Comment: <message/comment submitted by user>
*
* #param String $name name of submitter
* #param String $messsage message/comment submitted
*/
function setMessageBody ($first_name, $last_name, $email, $company_name,
$contact_message, $selectbasic) {
$message_body .= "First Name: " . $first_name."\n\n";
$message_body .= "Last Name: " . $last_name."\n\n";
$message_body .= "Email: " . $email."\n\n";
$message_body .= "Company Name:" . $company_name."\n\n";
$message_body .= "Message:" . $contact_message. "\n\n";
$message_body .= "How did you hear about us?" . $selectbasic."\n\n";
return $message_body;
}
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$company_name = $_POST['company_name'];
$contact_message = $_POST['contact_message'];
$selectbasic = $_POST['selectbasic'];
header('Content-type: application/json');
//do some simple validation. this should have been validated on the client-side also
if (empty($email) || empty($contact_message)) {
errorResponse('Email or message is empty.');
}
//do Captcha check, make sure the submitter is not a robot:)...
include_once './vender/securimage/securimage.php';
$securimage = new Securimage();
if (!$securimage->check($_POST['captcha_code'])) {
errorResponse('Invalid Security Code');
}
//try to send the message
if(mail(MY_EMAIL, "Contact Form Results", setMessageBody($_POST["first_name"],
$_POST["last_name"], $_POST["email"], $_POST["company_name"], $_POST["contact_message"],
$_POST["selectbasic"]), "From: $email")) {
echo json_encode(array('message' => 'Your message was successfully sent'));
} else {
header('HTTP/1.1 500 Internal Server Error');
echo json_encode(array('message' => 'Unexpected error while attempting to send e-
mail.'));
}
?>
JS code
$(document).ready(function() {
$("#feedbackSubmit").click(function() {
//clear any errors
contactForm.clearErrors();
//do a little client-side validation -- check that each field has a value and e-mail field is in proper format
var hasErrors = false;
$('#feedbackForm input,textarea').each(function() {
if (!$(this).val()) {
hasErrors = true;
contactForm.addError($(this));
}
});
var $email = $('#email');
if (!contactForm.isValidEmail($email.val())) {
hasErrors = true;
contactForm.addError($email);
}
//if there are any errors return without sending e-mail
if (hasErrors) {
return false;
}
//mailchimp trigger
if($('#emailUpdates').prop('checked')) {
$.ajax({
type: "POST",
url: 'subscribe.php',
data: 'ajax=true&email=' + escape($('#email').val())
});
}
//send the feedback e-mail
$.ajax({
type: "POST",
url: "library/sendmail.php",
data: $("#feedbackForm").serialize(),
success: function(data)
{
contactForm.addAjaxMessage(data.message, false);
//get new Captcha on success
$('#captcha').attr('src', 'library/vender/securimage/securimage_show.php?' +
Math.random());
},
error: function(response)
{
contactForm.addAjaxMessage(response.responseJSON.message, true);
}
});
$('#feedbackForm input,textarea,select').val('');
return false;
});
});
//namespace as not to pollute global namespace
var contactForm = {
isValidEmail: function (email) {
var regex = /^([a-zA-Z0-9_.+-])+\#(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
return regex.test(email);
},
clearErrors: function () {
$('#emailAlert').remove();
$('#feedbackForm .help-block').hide();
$('#feedbackForm .form-group').removeClass('has-error');
},
addError: function ($input) {
$input.siblings('.help-block').show();
$input.parent('.form-group').addClass('has-error');
},
addAjaxMessage: function(msg, isError) {
$("#feedbackSubmit").after('<div id="emailAlert" class="alert alert-' + (isError ?
'danger' : 'success') + '" style="margin-top: 5px;">' + $('<div/>').text(msg).html() +
'</div>');
}
};