the intention is submit a form using jQuery AJAX on a PHP page with the form validation part done with JQuery. The code as it stands now is as follows:
The HTML form:
[code]
<form class=”contactus-contactform validate-form” action=” ” method=”post” enctype=”text/plain” autocomplete=”off”>
<label class=”label-input” for=”name”>Full name *</label>
<div class=”contactfld-input validate-input” data-validate = “Name is required”>
<input class=”input-fld” id=”name” type=”text” name=”name” placeholder=”Enter your name”>
<span class=”focus-input”>
</span>
</div>
<!– // contactfld-input –>
<label class=”label-input” for=”phone”>contact number *</label>
<div class=”contactfld-input validate-input” data-validate = “Valid telephone number is required”>
<input class=”input-fld” id=”phone” type=”text” name=”phone” placeholder=”Enter your contact number”>
<span class=”focus-input”>
</span>
</div>
<!– // contactfld-input –>
<label class=”label-input” for=”email”>Email address *</label>
<div class=”contactfld-input validate-input” data-validate = “Valid email is required: [email protected]”>
<input class=”input-fld” id=”email” type=”text” name=”email” placeholder=”Eg. [email protected]”>
<span class=”focus-input”>
</span>
</div>
<!– // contactfld-input –>
<label class=”label-input” for=”email”>Subject *</label>
<div class=”contactfld-input mailsubject”>
<select class=”input-fld subjectselect” id=”emailsubject” name=”” onchange=”” onclick=”return false;” id=””>
<option value=””>Choose …</option>
<option value=”Table Reservations”>Table Reservations</option>
<option value=”Bookings”>Bookings</option>
<option value=”Party Hall Enquiry”>Party Hall Enquiry</option>
<option value=”Party Hall Booking”>Party Hall Booking</option>
<option value=”Catering Enquiry”>Catering Enquiry</option>
<option value=”Catering Arrangments”>Catering Arrangments</option>
<option value=”Catering Services”>Catering Services</option>
<option value=”Menu Orders”>Menu Orders</option>
<option value=”Banqueting Service Enquiry”>Banqueting Service Enquiry</option>
<option value=”Banqueting Arrangments”>Banqueting Arrangments</option>
<option value=”Online Enquiry”>Online Enquiry</option>
<option value=”Online Orders”>Online Orders</option>
<option value=”Online Order Ammendment”>Online Order Ammendment</option>
<option value=”Thoughts and Feedback”>Thoughts & Feedback</option>
<option value=”General Question”>General Question</option>
<option value=”Complaint”>Complaint</option>
</select>
<span class=”focus-input”>
</span>
</div>
<!– // contactfld-input –>
<div class=”add-informationrequired”>
<label class=”label-input” for=”tableno”>Table no/ Order Id </label>
<div class=”contactfld-input”>
<input class=”input-fld” id=”tableorder-idno” type=”text” name=”idno-tableorder” placeholder=””>
<span class=”focus-input”>
</span>
</div>
<!– // contactfld-input –>
</div>
<!– // add-informationrequired –>
<label class=”label-input” for=”message”>Message *</label>
<div class=”contactfld-input validate-input” data-validate = “Message is required”>
<textarea class=”input-fld” id=”message” name=”message” placeholder=”Type your message here…”></textarea>
<span class=”focus-input”>
</span>
</div>
<!– // contactfld-input –>
<div class=”container-contactform-submit-btn”>
<button class=”contactform-submit-btn submitmsgbtn”>
Send Message
</button>
<!– // contactform-submit-btn submitmsgbtn –>
</div>
<!– // container-contactform-submit-btn –>
</form>
<!– // contactus-contactform validate-form –>
and the JQuery for the validation part
[code]
(function ($) {
“use strict”;
var input = $(‘.validate-input .input-fld’);
$(‘.validate-form’).on(‘submit’,function(){
var check = true;
for(var i=0; i<input.length; i++) {
if(validate(input[i]) == false){
showValidate(input[i]);
check=false;
}
}
return check;
});
$(‘.validate-form .input-fld’).each(function(){
$(this).focus(function(){
hideValidate(this);
});
});
function validate(input) {
if ($(input).attr(‘type’) == ’email’ || $(input).attr(‘name’) == ’email’) {
<?php
if (empty($_POST[“email”]) {
echo ‘<script type=”text/javascript”>’,
‘showValidate(input);’,
‘</script>’;
} else {
$email = $_POST[“email”];
if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo ‘<script type=”text/javascript”>’,
‘showValidate(input);’,
‘</script>’;
}
}
?>
} else {
if ($(input).val().trim() == ”) {
return false;
}
}
}
// function validate(input)
function showValidate(input) {
var thisAlert = $(input).parent();
$(thisAlert).addClass(‘alert-validate’);
}
function hideValidate(input) {
var thisAlert = $(input).parent();
$(thisAlert).removeClass(‘alert-validate’);
}
})(jQuery);
but this for some reason throws the error: PHP Parse error: syntax error, unexpected ‘{‘ in /home/mnzsm9leak30/public_html/contact11.php on line 4757
which would be the line: if (empty($_POST[“email”]) within the function validate
could someone please give the function the once over with any pointers, ideas, or solution and yes i’m aware Icould have used a regex pattern but I opted to use php function and would prefer for it stay that way if possible