[guadec-web] adds validation to the registration form - props to Saumya Dwivedi (dvd)



commit 7bf722d92601b1daa14e4e76f50628e675d74edc
Author: Fabiana Simões <fabianapsimoes gmail com>
Date:   Sat Jul 5 12:35:24 2014 +0200

    adds validation to the registration form - props to Saumya Dwivedi (dvd)

 guadec/js/calculate-total.js |   52 ++++++++++++++++++++++++++++++++++++-----
 guadec/js/calculate.php      |    7 +++++
 2 files changed, 52 insertions(+), 7 deletions(-)
---
diff --git a/guadec/js/calculate-total.js b/guadec/js/calculate-total.js
index 7e3cf2d..40267f4 100644
--- a/guadec/js/calculate-total.js
+++ b/guadec/js/calculate-total.js
@@ -6,7 +6,7 @@
 function callTotalCalculate() {
        $.ajax({
        type: "POST",   
-       url:"wp-content/themes/guadec/js/calculate.php",
+       url:"../wp-content/themes/guadec/js/calculate.php",
        data: {functionname: "updateTotal", arguments : [$("form input[value*='lunch_']:checked").size(), 
$('#arrive').val(), $('#depart').val(), $('input:radio[name=entry-fee]:checked').val(), 
$("[value=lunch]").prop("checked"), $("[value=accommodation]").prop("checked"), 
$("[value=sponsored]").prop("checked") ]},
        success:function(obj, status){
                result = new String(obj);
@@ -25,7 +25,7 @@ function callTotalCalculate() {
 function callLunchCalculate() {
        $.ajax({
        type: "POST",   
-       url:"wp-content/themes/guadec/js/calculate.php",
+       url:"../wp-content/themes/guadec/js/calculate.php",
        data: {functionname : "updateLunchTotal", arguments : [$("form 
input[value*='lunch_']:checked").size(),  $("[value=lunch]").prop("checked")]},
        success:function(obj, status){
                result = new String(obj);
@@ -45,7 +45,7 @@ function callLunchCalculate() {
 function callAccomCalculate() {
        $.ajax({
        type: "POST",   
-       url:"wp-content/themes/guadec/js/calculate.php",
+       url:"../wp-content/themes/guadec/js/calculate.php",
        data: {functionname : "updateAccomTotal", arguments : [$('#arrive').val(),$('#depart').val(), 
$("[value=accommodation]").prop("checked"), $("[value=sponsored]").prop("checked")]},
        success:function(obj, status){
                result = new String(obj);
@@ -65,25 +65,41 @@ function enableDisableA(obj) {
        if ($(obj).is(":checked")) {
                $("#arrive").prop("disabled", false);
                $("#depart").prop("disabled", false);
+               $('[name=bday]').prop("disabled", false);
+               $("[name=sponsored]").prop("disabled", false);
+               $("[name=student]").prop("disabled", false);
+               $(".box-options-accom").removeClass("disabled");
+
        }
        else {
                $("#arrive").prop("disabled", true);
                $("#depart").prop("disabled", true);
+               $("[name=bday]").prop("disabled", true);
+               $("[name=sponsored]").prop("disabled", true);
+               $("[name=student]").prop("disabled", true);
+
+               $(".box-options-accom").addClass("disabled");
+
        }
 }
 
 function enableDisableL(obj) {
        if ($(obj).is(":checked")) {
                $("form input[value*='lunch_']").prop("disabled", false);
+               $("[name=diet]").prop("disabled", false);
+               $(".box-options-lunch").removeClass("disabled");
                
        }
        else {
                $("form input[value*='lunch_']").prop("disabled", true);
+               $("[name=diet]").prop("disabled", true);
+               $(".box-options-lunch").addClass("disabled");
                
        }
 }
 $(function() {
-       
+
+
        /*Dropdown triggered event*/
 
        $('#arrive').on('change' , function(){
@@ -111,14 +127,14 @@ $(function() {
        /*Radio triggered event */
        $('input:radio[name=entry-fee]').click(function() {
                callTotalCalculate();
-       })
+       });               
        
        $('#entry-arb').focusout(function(){
                if($('input:radio[id=entry-fee-arb]').is(':checked')){
                        $('input:radio[id=entry-fee-arb]').prop('value', $('#entry-arb').val()); 
                        callTotalCalculate();
                }
-       })
+       });
        /* To force entry of numbers in money textbox */
        $('#entry-arb').on('change keyup', function() {
          // Remove invalid characters
@@ -142,6 +158,7 @@ $(function() {
        });
        // Enable Disable the submit button
        $('input[name=regsub]').attr('disabled','disabled');
+
      $('input[name="policy"]').click(function() {
         if($(this).is(':checked')) {
            $('input[name=regsub]').removeAttr('disabled');
@@ -150,13 +167,34 @@ $(function() {
                $('input[name=regsub]').attr('disabled','disabled');
         }
      });
+
+     //Enable the arbitary Amount Text Field
+     $('#entry-arb').attr('disabled','disabled');
+     $('[name=entry-fee]').change(function(){
+       if($('input:radio[id=entry-fee-arb]').is(':checked')) {
+           $('#entry-arb').removeAttr('disabled');
+        }
+        else {
+               $('#entry-arb').attr('disabled','disabled');
+        }
+     });
+
+     /*Form Submit related checks */
      $('form[name=registration]').submit(function(event){
        if($("[value=accommodation]").is(':checked')){
-                       if(!$("[name=contact_country]").val()){
+                       if(!$("[name=contact_country]").val() || !$("[name=bday]").val()){
                                alert("Make sure you enter the birth country, date of birth and agree to 
anti-harassment policy");
                                event.preventDefault();
                        }
                }
+               if(!$("[name=contact_name]").val() || !$("[name=contact_email]").val()) {
+                       alert("Make sure you enter your name and email", $('.accomfee').html());
+                       event.preventDefault();
+               }
+               if($('.accomfee').html() == 'Incorrect dates'){
+                       alert("Make sure you enter correct accommodation dates");
+                       event.preventDefault(); 
+               }
      });
      
 });
diff --git a/guadec/js/calculate.php b/guadec/js/calculate.php
index 1ac8ca8..e38d413 100644
--- a/guadec/js/calculate.php
+++ b/guadec/js/calculate.php
@@ -66,6 +66,9 @@
                    else{ 
                      $total_days = dayParser($_POST['arguments'][0], $_POST['arguments'][1]);
                      $aResult = (int)($total_days) * day_fee;
+                     if ($total_days == "Incorrect dates"){
+                      $aResult = $total_days;
+                     }
                      
                   }
                }
@@ -88,6 +91,10 @@
                      $accom = 0;
                    }
                   $aResult = $accom + $lunch + (int)($_POST['arguments'][3]);
+                  if ($total_days == "Incorrect dates"){
+                      $aResult = $total_days;
+                  }
+                     
                }
                break;
             


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]