// Encoding: UTF-8 "use strict"; var allowSubmit = false; //This will execute when your page is loaded $(function(){ //Required attribute fallback var form = $("form"); form.submit(function() { // detect Safari browser var is_safari = navigator.userAgent.indexOf("Safari") > -1; var is_Opera = navigator.userAgent.indexOf("OPR") > -1; if (( navigator.userAgent.indexOf('Chrome') > -1 )&&(is_safari)) {is_safari=false;} if (is_safari || is_Opera) { //If required attribute is not supported or browser is Safari (Safari thinks that it has this attribute, but it does not work), then check all fields that has required attribute ($('input,textarea,select').filter('[required]')).each(function() { if (!$(this).val()) { //If at least one required value is empty, then ask to fill all required fields. alert("Please fill all required fields."); return false; } }); } return verify_form(); }); }); function capcha_filled () { allowSubmit = true; } function capcha_expired () { allowSubmit = false; } function hideBtn(){ //test if fields are not empty if($('#civility').val() != '' && $('#name').val() != '' && $('#firstname').val() != '' && $('#email').val() != '' && $('#phoneNumber').val() != ''){ $("#submit_btn").hide(); } } function check_if_capcha_is_filled () { if(allowSubmit) return true; alert("Captcha must be filled"); return false; } function isActivityFilled () { if($('#activityGroup :checkbox:checked').length > 0) { return true; } else { alert("At least one activity must be chosen"); return false; } } function isInterestFilled () { if($('#interestGroup :checkbox:checked').length > 0) { return true; } else { alert("At least one interest must be chosen"); return false; } } /** * verify_form * verify if the email provided is correct * @param boolean */ function verify_form(){ $("#submit_btn").hide(); //verify email var reg = new RegExp('^[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*@[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*([\.]{1}[a-z0-9]+)$', 'i'); if(!reg.test(document.getElementById("email").value)) { alert("The email address entered is incorrect"); $("#submit_btn").show(); return (false); } // check if there is at least one joint if (!isActivityFilled()) { $("#submit_btn").show(); return (false); } // check if there is at least one interest if (!isInterestFilled()) { $("#submit_btn").show(); return (false); } // check if captcha is filled if (!check_if_capcha_is_filled()) { $("#submit_btn").show(); return (false); } return true; }