From ebc442b10611c3cbbe3619c9852a3a7b73bb4def Mon Sep 17 00:00:00 2001 From: Anthony Talarico Date: Tue, 25 Apr 2017 09:05:16 -0400 Subject: [PATCH] adding poster form calculations 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 | 35 ++++++++++++++++++++++++++++++++++- js/app.js | 20 +++++--------------- js/custom/pageSetup.js | 20 +++++--------------- 3 files changed, 44 insertions(+), 31 deletions(-) diff --git a/functions.php b/functions.php index f2a800a..7263e88 100644 --- a/functions.php +++ b/functions.php @@ -345,5 +345,38 @@ function set_post_content( $entry, $form ) { echo ' View PDF '; } } +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 diff --git a/js/app.js b/js/app.js index 9a0768b..f9f933a 100644 --- 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 diff --git a/js/custom/pageSetup.js b/js/custom/pageSetup.js index bdc89ec..7173ad7 100644 --- a/js/custom/pageSetup.js +++ b/js/custom/pageSetup.js @@ -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 -- 2.17.1