PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Calculate cost based on chars in text area

  1. Hi,

    I'm using GF as a form to send advertisement text. I'd like to calculate the price based on the amount of characters in the main text area. The prices are calculated through this formula: EUR 7 for anything up to 60 characters; for each extra 20 characters we charge EUR 1,50. Max is 160 characters.

    I've been trying to get something like this going with conditional product fields, but didn't get that to work.

    Can you please help out by showing me how this can be done? I just need a small example and can copy/modify from there.

    Thanks!

    Posted 11 years ago on Monday April 23, 2012 | Permalink
  2. You might want to try playing around with the Beta that has support for calculations to see if it could solve for this:

    http://www.gravityhelp.com/gravity-forms-v1-6-4-beta-1-released/

    Posted 11 years ago on Monday April 23, 2012 | Permalink
  3. Hi Rob, I've been trying the new functions. This looks promising!

    I do need some help with setting up the basics of the formula. How can I refer to the Paragraph Text field and get the number of characters from that field?

    Posted 11 years ago on Monday April 23, 2012 | Permalink
  4. Also, a modulo function would be very useful in addition to the current calculation functions.

    Posted 11 years ago on Monday April 23, 2012 | Permalink
  5. Hi guys, any news on this one?

    Posted 11 years ago on Tuesday May 1, 2012 | Permalink
  6. Let me see if I can get any ideas on this one from the team. Sounds like it would potentially involve a customization of some kind.

    Posted 11 years ago on Tuesday May 1, 2012 | Permalink
  7. I think the following code snippet will point you in the right direction. My form had a textarea, a hidden product field and a total field.

    <script type="text/javascript">
    jQuery(document).ready(function(){
    	//NOTE: replace input_91_3 with the ID of your textarea
    	jQuery("#input_91_3").change(function(){
    		gformCalculateTotalPrice(91); //NOTE: replace 91 with your form ID
    	});
    });
    function gform_product_total(formId, total){
    
      //only apply logic to form ID 91
      if(formId != 91)
    	return total;
    
      var price = 0;
      //NOTE: replace input_91_3 with the ID of your textarea
      var character_count = jQuery("#input_91_3").val().length;
    
      if(character_count < 60){
    	price = 7;
      }
      else if(character_count < 80){
    	price = 8.5;
      }
      else if(character_count < 100){
    	price = 10;
      }
      else if(character_count < 120){
    	price = 11.5;
      }
      else if(character_count < 140){
    	price = 13;
      }
      else if(character_count < 160){
    	price = 14.5;
      }
    
      //NOTE: replace ginput_base_price_91_2 with the ID of your hidden product price field (you can see it by inspecting the markup of the form)
      jQuery("#ginput_base_price_91_2").val(price);
      return price;
    }
    </script>
    Posted 11 years ago on Tuesday May 1, 2012 | Permalink