/
var
/
www
/
html
/
stengineers
/
Upload FileeE
HOME
<?php header('Access-Control-Allow-Origin: *'); require_once 'admin/dbconnection.php'; error_reporting(0); // Add Google reCAPTCHA site key define('RECAPTCHA_SITE_KEY', '6LdpyB4sAAAAAFEGvTl7alj-dlsTn0qtlYbRGVw9'); $url = $_GET['product_title']; $row1 = mysqli_query($con, "select * from products as a where a.slug='$url'"); $row2 = mysqli_fetch_array($row1); $product_id = $row2['product_id']; $modal = $row2['modal']; $product_title = $row2['product_title']; $description = $row2['description']; $brouchure = $row2['brouchure']; $preview_image = $row2['preview_image']; $gal_img = $row2['product_gallery']; $status = $row2['status']; $categoryId = $row2['category']; $sub_category = $row2['sub_category']; $mrp = $row2['mrp']; $selling_price = $row2['selling_price']; $price_status = $row2['price_status']; $display_order = $row2['display_order']; $brand = $row2['brandid']; $feature1 = $row2['feature1']; $feature2 = $row2['feature2']; $feature3 = $row2['feature3']; $fdescription1 = $row2['fdescription1']; $fdescription2 = $row2['fdescription2']; $fdescription3 = $row2['fdescription3']; $video_link = $row2['video_link']; $row1_c = mysqli_query($con, "select * from category as a where a.id='$categoryId'"); $row2_c = mysqli_fetch_array($row1_c); $mcategory_name = $row2_c['category_name']; $murl = $row2_c['url']; $row1_sub = mysqli_query($con, "select * from category as a where a.id='$sub_category'"); $row2_sub = mysqli_fetch_array($row1_sub); $scategory_name = $row2_sub['category_name']; $surl = $row2_sub['url']; $title = ucwords($product_title) . " - " . ucwords($modal); $pagetitle = $product_title; $pageImage = $gal_img; $h1_title = $row2['h1_title']; $meta_title = $row2['pagetitle']; $metadescription = $row2['metadescription']; $metatags = $row2['metatags']; if($meta_title=="") { $pagetitle = "ST Engineers | $product_title"; } else { $pagetitle = $meta_title; } if($h1_title=="") { $h1tag = "$product_title"; } else { $h1tag = $h1_title; } require 'header.php'; ?> <!--Start Page Header--> <section class="single-product-banner"> <div class="d-flex flex-column align-items-center "> <div class="page-header__inner text-center"> <h1><?php echo ucwords($h1tag); ?></h1> </div> </div> </section> <!--End Page Header--> <!--Product Section Start--> <section class="single-product-sec"> <ol class="breadcrumb"> <li><a href="<?php echo $baseUrl; ?>products.php">Products</a></li> <li><a href="<?php echo $baseUrl; ?>category/<?php echo $murl; ?>"><?php echo ucwords($mcategory_name); ?></a></li> <li><a href="<?php echo $baseUrl; ?>subcategory/<?php echo $surl; ?>"><?php echo ucwords($scategory_name); ?></a></li> <li class="current"><?php echo ucwords($modal); ?></li> </ol> <div class="container"> <div class="row"> <h2><?php echo ucwords($modal); ?></h2> <h6><?php echo ucwords($product_title); ?></h6> <div id="carouselExampleInterval" class="carousel slide" data-bs-ride="carousel" style="margin-top: 25px;"> <div class="carousel-inner"> <?php if (substr($gal_img, 0, 1) === ',') { $gal_img = substr($gal_img, 1); } $gallery_array = explode(",", $gal_img); for ($i = 0; $i < count($gallery_array); $i++) { if ($gallery_array[$i] != "" && $gallery_array[$i] != ",") { if($i==0) { ?> <div class="carousel-item active" data-bs-interval="10000"> <img src="<?php echo $gallery_array[$i]; ?>" class="img-fluid w-70"> </div> <?php } else { ?> <div class="carousel-item" data-bs-interval="10000"> <img src="<?php echo $gallery_array[$i]; ?>" class="img-fluid w-70"> </div> <?php } } } ?> </div> <button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleInterval" data-bs-slide="prev"> <span class="carousel-control-prev-icon" aria-hidden="true"></span> <span class="visually-hidden">Previous</span> </button> <button class="carousel-control-next" type="button" data-bs-target="#carouselExampleInterval" data-bs-slide="next"> <span class="carousel-control-next-icon" aria-hidden="true"></span> <span class="visually-hidden">Next</span> </button> </div> </div><br> <div class="row col-lg-10 mx-auto"> <p><?php echo ucwords($description); ?></p> </div> <div class="row mt-5"> <div class="col-lg-4 mb-3 d-flex flex-column align-items-center"> <img src="<?php echo $imageUrl; ?>icons/star.png" class="img-fluid"> <h3><?php echo ucwords($feature1); ?></h3> <p><?php echo ucwords($fdescription1); ?></p> </div> <div class="col-lg-4 mb-3 d-flex flex-column align-items-center"> <img src="<?php echo $imageUrl; ?>icons/star.png" class="img-fluid"> <h3><?php echo ucwords($feature2); ?></h3> <p><?php echo ucwords($fdescription2); ?></p> </div> <div class="col-lg-4 mb-3 d-flex flex-column align-items-center"> <img src="<?php echo $imageUrl; ?>icons/star.png" class="img-fluid"> <h3><?php echo ucwords($feature3); ?></h3> <p><?php echo ucwords($fdescription3); ?></p> </div> <?php if ($brouchure != "") { ?> <a class="single-product-btn " style="width: 23%; cursor: pointer;" onclick="downloadbrouch('<?php echo $brouchure; ?>')">Download Brochure<img src="<?php echo $imageUrl; ?>home/btn-arrow.png" alt="" class="arrow-img1"></a> <?php } ?> </div> </div> <!-- popup content start --> <div class="modal fade" id="modalform_p" tabindex="-1" aria-labelledby="modalformLabel" aria-hidden="true"> <div class="modal-dialog modal-dialog-centered"> <div class="modal-content"> <div class="modal-body"> <button type="button" class="close" id="close_btn_p" data-bs-dismiss="modal" aria-label="Close"> <img src="<?php echo $imageUrl; ?>cancel.png"> </button> <div class="form_sec centered_content" style="align-items:end;"> <form class="form-contact contact_form" id="enq_form_p" novalidate="novalidate"> <h5> Enquiry Form </h5> <div class="row"> <input type="hidden" class="form-control" name="pageSource" id="e_pageSource_p" value="<?php echo $pagetitle; ?>"> <input type="hidden" id="g-recaptcha-response_p" name="g-recaptcha-response"> <div class="col-sm-6"> <div class="form-group"> <input class="form-control " name="name" id="e_name_p" type="text" placeholder="Name*"> <span style="color: red; font-size: 12px;" class="errorform" id="e_name_Err_p"></span> </div> </div> <div class="col-sm-6"> <div class="form-group"> <input class="form-control " name="company" id="e_company_p" type="text" placeholder="Company*"> <span style="color: red; font-size: 12px;" class="errorform" id="e_company_Err_p"></span> </div> </div> <div class="col-sm-6"> <div class="form-group"> <input class="form-control " name="email" id="e_email_p" type="email" placeholder="Email ID*"> <span style="color: red; font-size: 12px;" class="errorform" id="e_email_Err_p"></span> </div> </div> <div class="col-sm-6"> <div class="form-group"> <input class="form-control " name="mobile" id="e_mobile_p" type="tel" inputmode="tel" placeholder="Phone Number*"> <span style="color: red; font-size: 12px;" class="errorform" id="e_mobile_Err_p"></span> </div> </div> <div class="col-sm-6"> <div class="form-group"> <input class="form-control " name="country" id="e_country_p" type="text" placeholder="Country*"> <span style="color: red; font-size: 12px;" class="errorform" id="e_country_Err_p"></span> </div> </div> <div class="col-sm-6"> <div class="form-group"> <input class="form-control " name="pincode" id="e_pincode_p" type="text" placeholder="Pin Code*"> <span style="color: red; font-size: 12px;" class="errorform" id="e_pincode_Err_p"></span> </div> </div> <div class="col-12"> <div class="form-group"> <input class="form-control" name="product" id="e_product_p" type="text" placeholder="Product" value="<?php echo $product_title; ?>"> <span style="color: red; font-size: 12px;" class="errorform" id="e_product_Err_p"></span> </div> </div> <div class="col-12"> <div class="form-group mt-25"> <textarea class="form-control w-100" name="message" id="e_message_p" cols="30" rows="4" placeholder="Message"></textarea> <span style="color: red; font-size: 12px;" class="errorform" id="e_message_Err_p"></span> </div> </div> </div> <div class="form-group mt-3 text-center"> <!-- Google reCAPTCHA WITH CALLBACK --> <div class="g-recaptcha" data-sitekey="<?php echo RECAPTCHA_SITE_KEY; ?>" data-callback="onCaptchaSuccess_p"></div> <span id="recaptcha-error_p" style="color:red; font-size:12px;"></span> </div> <!-- Submit btn --> <div class="form-group mt-3"> <button type="button" class="boxed-btn" id="add-submit_p">SUBMIT</button> <div id="succ-client-alert_p" style="color: green;padding: 6px 0px 0px 16px;text-align:center"></div> <div id="fail-client-alert_p" style="color: red;padding: 6px 0px 0px 16px;text-align:center"></div> </div> </form> </div> </div> </div> </div> </div> </section> <!--Product Section End--> <!--Product Specification Section Start--> <section class="product-specs"> <div class="container"> <div class="row"> <h2>SPECIFICATION</h2> <div class="specs"> <div class="col-lg-4 col-md-5 col-5"><h5><?php echo ucwords($modal); ?></h5></div> <div class="col-lg-2 col-md-2 col-3 d-flex justify-content-center"><h5>Unit</h5></div> <div class="col-lg-6 col-md-5 col-4"><h5>Values</h5></div> </div> </div> <div class="row"> <div class="accordion px-0" id="accordionExample"> <?php $i = "1"; $result = $con->query("SELECT * FROM specification WHERE product_id='$product_id'"); while ($row = $result->fetch_assoc()) { $title_s = $row['title']; $id_s = $row['id']; if ($i == 1) { $show = "show"; $collapsed = ""; } else { $show = ""; $collapsed = "collapsed"; } ?> <div class="accordion-item"> <h2 class="accordion-header" id="heading<?php echo $i; ?>"> <button class="accordion-button <?php echo $collapsed; ?>" type="button" data-bs-toggle="collapse" data-bs-target="#collapse<?php echo $i; ?>" aria-expanded="true" aria-controls="collapse<?php echo $i; ?>"><?php echo ucwords($title_s); ?></button> </h2> <div id="collapse<?php echo $i; ?>" class="accordion-collapse collapse overflow-auto <?php echo $show; ?>" aria-labelledby="heading<?php echo $i; ?>" data-bs-parent="#accordionExample"> <?php $result_sv = $con->query("SELECT * FROM specification_value WHERE specs_id='$id_s'"); while ($row_sv = $result_sv->fetch_assoc()) { $field1 = implode('-', array_map('ucfirst', explode('-', $row_sv['field1']))); $field2 = $row_sv['field2']; $field3 = $row_sv['field3']; $field4 = $row_sv['field4']; ?> <div class="accordion-body"> <div class="col-lg-4 col-md-5 col-5"><?php echo ucwords($field1); ?></div> <div class="col-lg-2 col-md-2 col-3 d-flex justify-content-center text-lowercase"><?php echo ucwords($field2); ?></div> <div class="col-lg-6 col-md-5 col-4"><?php echo ucwords($field3); ?></div> </div> <?php } $i++; echo "</div></div>"; } ?> </div> <a class="quote-btn" id="prod_enquiry" style="cursor: pointer;" class="side_enquiry">Get Quote<img src="<?php echo $imageUrl; ?>home/btn-arrow.png" alt="" class="arrow-img1"></a> </div> </section> <!--Product Specification Section Start--> <!--Product Details Section Start--> <section class="product-detail-sec"> <div class="container"> <div class="row"> <?php $ifeat = "0"; $result_f = $con->query("SELECT * FROM product_feature WHERE product_id='$product_id' ORDER BY feature_order asc"); while ($row_f = $result_f->fetch_assoc()) { $feature_data = $row_f['feature_data']; $feature_image = $row_f['image']; if($feature_data!="" && $feature_image!="") { if ($ifeat % 2 == 0) { ?> <div class="col-lg-6 col-md-6 px-0 pr-10 my-auto d-none d-md-block"> <?php echo $feature_data; ?> </div> <div class="col-lg-6 col-md-6 px-0"> <img src="<?php echo $feature_image; ?>" class="img-fluid"> </div> <div class="col-lg-6 col-md-6 px-0 pr-10 my-auto d-block d-md-none"> <?php echo $feature_data; ?> </div> <?php } else { ?> <div class="col-lg-6 col-md-6 px-0"> <img src="<?php echo $feature_image; ?>" class="img-fluid"> </div> <div class="col-lg-6 col-md-6 px-0 my-auto"> <?php echo $feature_data; ?> </div> <?php } $ifeat++; } } ?> </div> </div> </section> <!--Product Details Section End--> <!--Product Video Section start--> <section class="product-video"> <div class="container"> <div class="row col-lg-10 mx-auto"> <?php if ($video_link == "") { ?> <iframe class="single-video" src="https://www.youtube.com/embed/yxQXv00U2lo?si=bIYxJ8nqdWy491fl" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe> <?php } else { echo $video_link; } ?> </div> </div> </section> <!--Product Video Section End--> <!--Start blogs--> <section class="related-access"> <div class="container-fluid"> <div class="row"> <h2>RELATED PRODUCTS</h2> </div> <div class="row col-lg-10 col-md-10 col-9 mx-auto"> <!-- Slider main container --> <div class="swiper-container swiper"> <!-- Additional required wrapper --> <div class="swiper-wrapper"> <?php $s = "select * from related_products where product_id='$product_id'"; $res = mysqli_query($con, $s); $num = mysqli_num_rows($res); if ($num == 0) { $productQuery = $con->query("SELECT * FROM products where status='active' order by RAND() limit 5"); while ($productRow = $productQuery->fetch_assoc()) { $productName = $productRow['product_title']; $machineImg = $productRow['preview_image']; $brandproID = $productRow['brandid']; $slug = $productRow['slug']; if ($slug != $url) { echo "<div class='swiper-slide'><a href='" . $baseUrl . "product/$slug'> <img src='$machineImg' class='img-fluid'> <h5>" . ucwords($productName) . "</h5></a> </div>"; } } } else { $relProductQuery = $con->query("select * from related_products where product_id='$product_id'"); while ($relProductRow = $relProductQuery->fetch_assoc()) { $related_prod_id = $relProductRow['related_prod_id']; $productQuery = mysqli_query($con, "SELECT * FROM products where product_id='$related_prod_id'"); $productRow = mysqli_fetch_array($productQuery); $productName = $productRow['product_title']; $machineImg = $productRow['preview_image']; $brandproID = $productRow['brandid']; $slug = $productRow['slug']; echo "<div class='swiper-slide'><a href='" . $baseUrl . "product/$slug'> <img src='$machineImg' class='img-fluid'> <h5>" . ucwords($productName) . "</h5></a> </div>"; } } ?> </div> <!-- If we need navigation buttons --> </div> <div class="swiper-nav-wrapper"> <div class="swiper-button-prev"></div> <div class="swiper-button-next"></div> </div> </div> </div> </section> <!--End blogs--> <?php require 'footer.php';?> <!-- Add reCAPTCHA script --> <script src="https://www.google.com/recaptcha/api.js" async defer></script> <script> // Global variables let iti; // For intlTelInput instance let isFormSubmitting = false; // reCAPTCHA callback function - THIS IS CRITICAL function onCaptchaSuccess_p(response) { // Set the reCAPTCHA response token to the hidden input $('#g-recaptcha-response_p').val(response); // Clear any reCAPTCHA error $('#recaptcha-error_p').text(''); console.log("reCAPTCHA completed successfully"); } // Open modal functions function downloadbrouch(fname) { // Create a hidden input if it doesn't exist if ($('#brouchure_file_name').length === 0) { $('<input type="hidden" name="brouchure_file_name" id="brouchure_file_name" value="">').appendTo('#enq_form_p'); } $('#brouchure_file_name').val(fname); $('#modalform_p').modal('show'); // Reset reCAPTCHA when modal opens setTimeout(() => { if (typeof grecaptcha !== 'undefined' && grecaptcha.reset) { grecaptcha.reset(); } $('#g-recaptcha-response_p').val(''); $('#recaptcha-error_p').text(''); }, 300); } // Initialize when document is ready $(document).ready(function() { // Swiper initialization if (typeof Swiper !== 'undefined') { new Swiper('.swiper-container', { observer: true, observeParents: true, parallax: true, loop: false, navigation: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev', }, slidesPerView: 3, paginationClickable: true, spaceBetween: 20, breakpoints: { 1500: { slidesPerView: 4, spaceBetween: 30 }, 1024: { slidesPerView: 3, spaceBetween: 30 }, 760: { slidesPerView: 2, spaceBetween: 30 }, 350: { slidesPerView: 1, spaceBetween: 30 } } }); } // Phone input initialization var phoneInputID = "#e_mobile_p"; var input = document.querySelector(phoneInputID); if (input) { iti = window.intlTelInput(input, { formatOnDisplay: true, autoHideDialCode: false, autoPlaceholder: "polite", placeholderNumberType: "MOBILE", initialCountry: "in", preferredCountries: ['in', 'us', 'gb'], separateDialCode: true, utilsScript: "https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/11.0.14/js/utils.js" }); // STRICT INPUT RESTRICTION: ONLY NUMBERS, +, AND SPACES $(phoneInputID).on('input', function() { let value = $(this).val(); // 1. Remove all letters and invalid characters (only keep digits, +, spaces) let newValue = value.replace(/[^\d+\s]/g, ''); // 2. If user tries to type letters, show error immediately if (value !== newValue) { // Show error message $('#e_mobile_Err_p').text('Only numbers allowed (10-15 digits)'); // Remove the invalid characters $(this).val(newValue); } else { // Clear error if valid $('#e_mobile_Err_p').text(''); } // 3. Get digits only count const digitsOnly = newValue.replace(/\D/g, ''); // 4. If more than 15 digits, truncate if (digitsOnly.length > 15) { let truncated = ''; let digitCount = 0; // Build new value with max 15 digits for (let i = 0; i < newValue.length; i++) { if (newValue[i].match(/\d/)) { if (digitCount < 15) { truncated += newValue[i]; digitCount++; } } else { truncated += newValue[i]; } } $(this).val(truncated); $('#e_mobile_Err_p').text('Maximum 15 digits allowed'); } // 5. Validate phone format validatePhoneField(); }); // Add blur event for validation $(phoneInputID).on('blur', function() { validatePhoneField(); }); // Also validate when country changes input.addEventListener('countrychange', function() { validatePhoneField(); }); } // Get Quote button event listener $('#prod_enquiry').on('click', function() { // Remove any existing brochure file name $('#brouchure_file_name').remove(); $('#modalform_p').modal('show'); // Reset reCAPTCHA when modal opens setTimeout(() => { if (typeof grecaptcha !== 'undefined' && grecaptcha.reset) { grecaptcha.reset(); } $('#g-recaptcha-response_p').val(''); $('#recaptcha-error_p').text(''); }, 300); }); // Submit button event listener $('#add-submit_p').on('click', function() { submitEnquiryForm(); }); // Real-time validation for each field $('#e_name_p').on('blur', validateNameField); $('#e_company_p').on('blur', validateCompanyField); $('#e_email_p').on('blur', validateEmailField); $('#e_country_p').on('blur', validateCountryField); $('#e_pincode_p').on('blur', validatePincodeField); $('#e_message_p').on('blur', validateMessageField); // Handle Enter key in form $('#enq_form_p').on('keypress', function(e) { if (e.which === 13) { e.preventDefault(); if (!isFormSubmitting) { submitEnquiryForm(); } } }); // Reset form when modal closes $('#modalform_p').on('hidden.bs.modal', function() { resetForm(); }); }); // Individual field validation functions function validateNameField() { const name = $('#e_name_p').val().trim(); const errorElement = $('#e_name_Err_p'); if (!name) { errorElement.text('Name is required'); return false; } if (name.length < 2) { errorElement.text('Name must be at least 2 characters'); return false; } if (!/^[a-zA-Z\s]+$/.test(name)) { errorElement.text('Name can only contain letters and spaces'); return false; } errorElement.text(''); return true; } function validateCompanyField() { const company = $('#e_company_p').val().trim(); const errorElement = $('#e_company_Err_p'); if (!company) { errorElement.text('Company name is required'); return false; } if (company.length < 2) { errorElement.text('Company name must be at least 2 characters'); return false; } errorElement.text(''); return true; } function validateEmailField() { const email = $('#e_email_p').val().trim(); const errorElement = $('#e_email_Err_p'); if (!email) { errorElement.text('Email is required'); return false; } if (!validateEmail(email)) { errorElement.text('Please enter a valid email address'); return false; } errorElement.text(''); return true; } function validatePhoneField() { const phone = $('#e_mobile_p').val().trim(); const errorElement = $('#e_mobile_Err_p'); if (!phone) { errorElement.text('Phone number is required'); return false; } // Check for letters in the input if (/[a-zA-Z]/.test(phone)) { errorElement.text('Phone number cannot contain letters'); return false; } // Get the actual phone number (with intlTelInput if available) let phoneNumber = phone; if (typeof iti !== 'undefined') { phoneNumber = iti.getNumber() || phone; } // STRICT VALIDATION: 10-15 DIGITS ONLY if (!validatePhoneNumber(phoneNumber)) { errorElement.text('Please enter a valid phone number (10-15 digits only)'); return false; } errorElement.text(''); return true; } function validateCountryField() { const country = $('#e_country_p').val().trim(); const errorElement = $('#e_country_Err_p'); if (!country) { errorElement.text('Country is required'); return false; } if (country.length < 2) { errorElement.text('Please enter a valid country name'); return false; } errorElement.text(''); return true; } function validatePincodeField() { const pincode = $('#e_pincode_p').val().trim(); const errorElement = $('#e_pincode_Err_p'); if (!pincode) { errorElement.text('Pin Code is required'); return false; } if (!/^\d{4,10}$/.test(pincode)) { errorElement.text('Please enter a valid pin code (4-10 digits)'); return false; } errorElement.text(''); return true; } function validateMessageField() { const message = $('#e_message_p').val().trim(); const errorElement = $('#e_message_Err_p'); if (message.length > 1000) { errorElement.text('Message must be less than 1000 characters'); return false; } errorElement.text(''); return true; } // Phone number validation function - STRICT 10-15 DIGITS ONLY function validatePhoneNumber(phone) { // Remove all non-digit characters (only keep numbers) const digitsOnly = phone.replace(/\D/g, ''); // Check length - must be exactly 10-15 digits if (digitsOnly.length < 10 || digitsOnly.length > 15) { return false; } // Check if it contains only digits return /^\d+$/.test(digitsOnly); } // Email validation function function validateEmail(email) { var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return re.test(String(email).toLowerCase()); } // Main enquiry submission function with complete validation function submitEnquiryForm() { // Prevent multiple submissions if (isFormSubmitting) return; // Clear all previous error messages $('.errorform').html(''); $('#succ-client-alert_p').html(''); $('#fail-client-alert_p').html(''); $('#recaptcha-error_p').html(''); let hasError = false; // Get form values const name = $('#e_name_p').val().trim(); const company = $('#e_company_p').val().trim(); const email = $('#e_email_p').val().trim(); const phone = $('#e_mobile_p').val().trim(); const country = $('#e_country_p').val().trim(); const pincode = $('#e_pincode_p').val().trim(); const product = $('#e_product_p').val().trim(); const message = $('#e_message_p').val().trim(); const pageSource = $('#e_pageSource_p').val(); const brochureFile = $('#brouchure_file_name').val() || ''; // Validate Name if (!validateNameField()) hasError = true; // Validate Company if (!validateCompanyField()) hasError = true; // Validate Email if (!validateEmailField()) hasError = true; // STRICT PHONE VALIDATION if (!phone) { $('#e_mobile_Err_p').text('Phone number is required'); hasError = true; } else { // Check for letters in phone number if (/[a-zA-Z]/.test(phone)) { $('#e_mobile_Err_p').text('Phone number cannot contain letters'); hasError = true; } else { // Get full number from intlTelInput if available let fullPhoneNumber = phone; if (typeof iti !== 'undefined') { fullPhoneNumber = iti.getNumber() || phone; } // STRICT VALIDATION: 10-15 DIGITS ONLY if (!validatePhoneNumber(fullPhoneNumber)) { $('#e_mobile_Err_p').text('Please enter a valid phone number (10-15 digits only)'); hasError = true; } } } // Validate Country if (!validateCountryField()) hasError = true; // Validate Pin Code if (!validatePincodeField()) hasError = true; // Validate Message if (!validateMessageField()) hasError = true; // Validate reCAPTCHA - Check the hidden input value const captchaResponse = $('#g-recaptcha-response_p').val(); if (!captchaResponse || captchaResponse.trim() === '') { $('#recaptcha-error_p').text('Please complete the reCAPTCHA verification.'); hasError = true; } // If any validation errors, stop submission if (hasError) { console.log("Validation errors found"); return false; } // Set submitting state isFormSubmitting = true; const submitBtn = $('#add-submit_p'); submitBtn.prop('disabled', true).text('Submitting...'); // Get full phone number from intlTelInput if available let fullPhoneNumber = phone; if (typeof iti !== 'undefined') { fullPhoneNumber = iti.getNumber() || phone; } // Prepare form data as FormData object const formData = new FormData(); formData.append('name', name); formData.append('company', company); formData.append('email', email); formData.append('mobile', fullPhoneNumber); formData.append('country', country); formData.append('pincode', pincode); formData.append('product', product); formData.append('message', message); formData.append('g-recaptcha-response', captchaResponse); formData.append('pageSource', pageSource); if (brochureFile) { formData.append('brochure', brochureFile); } console.log("Form data prepared, captcha token:", captchaResponse ? "Present" : "Missing"); // Submit via AJAX $.ajax({ type: "POST", url: "https://stengineers.com/admin/api/insertenquiry.php", data: formData, processData: false, contentType: false, dataType: "json", success: function(response) { isFormSubmitting = false; submitBtn.prop('disabled', false).text('SUBMIT'); console.log("Server response:", response); if (response.status === true) { // Show success message $('#succ-client-alert_p').html(` <div style="background: #d4edda; color: #155724; padding: 12px; border-radius: 5px; border: 1px solid #c3e6cb;"> <strong>Thank You!</strong> Your enquiry has been submitted successfully! <br> <small>Redirecting to thank you page...</small> </div> `); // Reset form $('#enq_form_p')[0].reset(); // Reset phone input if (typeof iti !== 'undefined') { iti.setNumber(""); } // Reset reCAPTCHA if (typeof grecaptcha !== 'undefined' && grecaptcha.reset) { grecaptcha.reset(); } $('#g-recaptcha-response_p').val(''); // After 1.5 seconds, close the modal and redirect to thank you page setTimeout(function() { $('#succ-client-alert_p').text(''); $('#modalform_p').modal('hide'); // Redirect to thank you page window.location.href = "https://stengineers.com/thank-you/"; }, 1500); } else { // Display server error message $('#fail-client-alert_p').text(response.message || 'Failed to send enquiry.'); // Reset reCAPTCHA on error if (typeof grecaptcha !== 'undefined' && grecaptcha.reset) { grecaptcha.reset(); } $('#g-recaptcha-response_p').val(''); $('#recaptcha-error_p').text(''); } }, error: function(xhr, status, error) { isFormSubmitting = false; submitBtn.prop('disabled', false).text('SUBMIT'); console.error('AJAX Error:', status, error); console.error('XHR response:', xhr.responseText); let errorMessage = 'An error occurred. Please try again.'; // Try to parse error response if it's JSON try { const errorResponse = JSON.parse(xhr.responseText); if (errorResponse.message) { errorMessage = errorResponse.message; } } catch (e) { // If not JSON, use default message } $('#fail-client-alert_p').text(errorMessage); // Reset reCAPTCHA if (typeof grecaptcha !== 'undefined' && grecaptcha.reset) { grecaptcha.reset(); } $('#g-recaptcha-response_p').val(''); $('#recaptcha-error_p').text(''); } }); } // Reset form function function resetForm() { // Reset form fields $('#enq_form_p')[0].reset(); // Reset phone input if (typeof iti !== 'undefined') { iti.setNumber(""); } // Reset reCAPTCHA if (typeof grecaptcha !== 'undefined' && grecaptcha.reset) { grecaptcha.reset(); } $('#g-recaptcha-response_p').val(''); // Clear messages $('.errorform').html(''); $('#succ-client-alert_p').html(''); $('#fail-client-alert_p').html(''); $('#recaptcha-error_p').html(''); // Reset submitting state isFormSubmitting = false; // Re-enable submit button $('#add-submit_p').prop('disabled', false).text('SUBMIT'); } </script>