adding poster form calculations
authorAnthony Talarico <talarico@gaslightmedia.com>
Tue, 25 Apr 2017 13:05:16 +0000 (09:05 -0400)
committerAnthony Talarico <talarico@gaslightmedia.com>
Tue, 25 Apr 2017 13:05:16 +0000 (09:05 -0400)
adding javascript to change the total on the form so the user can see what
the new total is. using pre submission gravity form hook to change the total
for the gravity pdf

functions.php
js/app.js
js/custom/pageSetup.js

index f2a800a..7263e88 100644 (file)
@@ -345,5 +345,38 @@ function set_post_content( $entry, $form ) {
         echo '<a class="pdf-form button" href="' . $url . '"> View PDF </a>';
     }
 }
+add_action( 'gform_pre_submission_2', 'change_post_content', 10, 2 );
+function change_post_content( $form ) {
+
+    $fields = array(
+        'input_3_2'=>'input_3_3',
+        'input_7_2'=>'input_7_3',
+        'input_6_2'=>'input_6_3',
+        'input_5_2'=>'input_5_3',
+        'input_19_2'=>'input_19_3',
+        'input_18_2'=>'input_18_3',
+        'input_17_2'=>'input_17_3',
+        'input_16_2'=>'input_16_3'
+    );
+    foreach($fields as $key=>$value){
+        
+        $prod_quantity = $_POST[$value];
+        
+        if( $prod_quantity ){
+            $populated_fields[$key] = array('price'=>$_POST[$key], 'qty'=>$_POST[$value]);
+        } 
+    }
 
-?>
+    foreach($populated_fields as $price=>$info){
+        if( $info['qty'] > 1 ){
+            $prod_price = $info['qty'] * 10 - 10;
+            $prod_price = $prod_price / $info['qty'];
+            $_POST[$price] = $prod_price;
+            return;
+        } else {
+             $_POST[$price] = '$0.00';
+            return;
+        }
+    }
+}
+?>
\ No newline at end of file
index 9a0768b..f9f933a 100644 (file)
--- a/js/app.js
+++ b/js/app.js
@@ -56,6 +56,8 @@ $(document).ready(function () {
     pdf_form.insertAfter(".gform_confirmation_message");
     pdf_form.css("display", "block");
     
+    
+    // globals
     var poster_form     = page.find("#gform_2");
     var poster_input    = poster_form.find('.ginput_quantity');
     var prod_values     = [];
@@ -82,7 +84,7 @@ $(document).ready(function () {
        } else if( qty_total < 4){
            price_total = qty_total * 10;
        }
-
+        
        $('.ginput_total_2').text('$' + price_total + '.00');
        $('#input_2_15').val(price_total);
     }
@@ -96,22 +98,10 @@ $(document).ready(function () {
             quantity += parseInt($(this).val());
         }
        $(document).on("change",$(this),calculate_poster);
-        if( $(this).val() ){
-            prod_values.push($(this));
-        }
+
     });
+    
 
-    if(quantity >= 4){
-        $.each(prod_values.slice(0,1), function(){
-            if( $(this).val() === '1'){
-                $(this).prev().prev().val('0');
-            } else {
-                var price_calc =  parseInt( $(this).val() ) * 10 - 10;
-                var new_price =  ( price_calc / parseInt( $(this).val() ) );
-                $(this).prev().prev().val( new_price );
-            }
-        }); 
-    }
     //end poster form calculations ///////////////////////////////////
 
     // token order form
index bdc89ec..7173ad7 100644 (file)
@@ -47,6 +47,8 @@ $(document).ready(function () {
     pdf_form.insertAfter(".gform_confirmation_message");
     pdf_form.css("display", "block");
     
+    
+    // globals
     var poster_form     = page.find("#gform_2");
     var poster_input    = poster_form.find('.ginput_quantity');
     var prod_values     = [];
@@ -73,7 +75,7 @@ $(document).ready(function () {
        } else if( qty_total < 4){
            price_total = qty_total * 10;
        }
-
+        
        $('.ginput_total_2').text('$' + price_total + '.00');
        $('#input_2_15').val(price_total);
     }
@@ -87,22 +89,10 @@ $(document).ready(function () {
             quantity += parseInt($(this).val());
         }
        $(document).on("change",$(this),calculate_poster);
-        if( $(this).val() ){
-            prod_values.push($(this));
-        }
+
     });
+    
 
-    if(quantity >= 4){
-        $.each(prod_values.slice(0,1), function(){
-            if( $(this).val() === '1'){
-                $(this).prev().prev().val('0');
-            } else {
-                var price_calc =  parseInt( $(this).val() ) * 10 - 10;
-                var new_price =  ( price_calc / parseInt( $(this).val() ) );
-                $(this).prev().prev().val( new_price );
-            }
-        }); 
-    }
     //end poster form calculations ///////////////////////////////////
 
     // token order form