adding dynamically populated discounted total form input
authorAnthony Talarico <talarico@gaslightmedia.com>
Thu, 27 Apr 2017 18:22:58 +0000 (14:22 -0400)
committerAnthony Talarico <talarico@gaslightmedia.com>
Thu, 27 Apr 2017 18:22:58 +0000 (14:22 -0400)
adding a new input field to the poster form to add a discounted calculation total to
the new field. using a gravity pdf hook to append the data to the form after generation

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

index 04cc3e5..f5ea1c9 100644 (file)
@@ -368,31 +368,38 @@ function change_post_content( $form ) {
     }
     // loop through the populated fields to calc the qty
     $quantity = 0;
-    foreach($populated_fields as $price=>$info){
-        $quantity += $info['qty'];
-    }
-    
-    // logic to determine the discount rate, every 4 gets $10 off
-    if($quantity % 4 === 0){
-       $discount_qty = $quantity / 4;
-       $discount_price = $discount_qty * 10;
-       $price_total = ($quantity * 10) - $discount_price;
-
-    } else if( $quantity > 4 && $quantity % 4 !== 0){
-       $discount_qty = floor($quantity / 4);
-       $discount_price = $discount_qty * 10;
-       $price_total = ($quantity * 10) - $discount_price;
-     
-    } else if( $quantity < 4){
-       $price_total = $quantity * 10;
-    }
-    
-    $new_price = $price_total / $quantity;
-    
-    // set the newly calulated price for pdf form
-    foreach($populated_fields as $price=>$info){
-        $_POST[$price] = $new_price;
-    }
+//    foreach($populated_fields as $price=>$info){
+//        $quantity += $info['qty'];
+//    }
+//    
+//    // logic to determine the discount rate, every 4 gets $10 off
+//    if($quantity % 4 === 0){
+//       $discount_qty = $quantity / 4;
+//       $discount_price = $discount_qty * 10;
+//       $price_total = ($quantity * 10) - $discount_price;
+//
+//    } else if( $quantity > 4 && $quantity % 4 !== 0){
+//       $discount_qty = floor($quantity / 4);
+//       $discount_price = $discount_qty * 10;
+//       $price_total = ($quantity * 10) - $discount_price;
+//     
+//    } else if( $quantity < 4){
+//       $price_total = $quantity * 10;
+//    }
+//    
+//    $new_price = $price_total / $quantity;
+//    
+//    // set the newly calulated price for pdf form
+//    foreach($populated_fields as $price=>$info){
+//        $_POST[$price] = $new_price;
+//    }
     
 }
+add_action( 'gfpdf_post_html_fields', function( $entry, $config ) {
+        if($entry['form_id'] === '2'){
+            echo "<div class='gf_right_half' style='font-weight: bold;width: 200px;margin-right: 10px;color: black;'> DISCOUNTED TOTAL: " . $entry['21'] . "</div>";
+        }
+       
+    
+}, 10, 2 );
 ?>
\ No newline at end of file
index 2c2caeb..5c80b93 100644 (file)
--- a/js/app.js
+++ b/js/app.js
@@ -91,8 +91,8 @@ $(document).ready(function () {
            price_total = qty_total * 10;
        }
         
-       $('.ginput_total_2').text('$' + price_total + '.00');
-       $('#input_2_15').val(price_total);
+       $('#input_5_20').text('$' + price_total + '.00');
+       $('#input_5_20').val('$' + price_total + '.00');
     }
   
     $(window).on("load", function(){
index 5028757..096a3dd 100644 (file)
@@ -82,8 +82,8 @@ $(document).ready(function () {
            price_total = qty_total * 10;
        }
         
-       $('.ginput_total_2').text('$' + price_total + '.00');
-       $('#input_2_15').val(price_total);
+       $('#input_5_20').text('$' + price_total + '.00');
+       $('#input_5_20').val('$' + price_total + '.00');
     }
   
     $(window).on("load", function(){