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.

Conditionals or Calculations?

  1. ameeker
    Member

    I received a request from a client for a custom form today and thought I’d ask for some direction on the best way to make it happen. Here’s the request:

    Guest submits the amount they spend annually on shipping (along with some other basic info)
    1% of that amount becomes the membership dues (min of $200, rounded down in chunks of $5,000) IE, someone spending $1 - $24,999 pays $200, and someone spending $25,000 - $29,999 pays $250
    The membership dues figure is shown/submitted along with other info collected.

    I know this could be done using just conditionals in the second field (if Number 1 is between x and y then z), but wondered if there was a better way to accomplish what they’re looking for… since they will be dealing with clients whose annual spend ranges from tens of thousands to tens of millions – they need to scale that formula indefinitely. Inputting those individual conditionals seems like the wrong way to do it-a formula using the calculations seems better, but I can’t quite get my head on that yet…only because of the need to place the annual spend in the “between x and y.” If it wasn’t for that, obviously it’s a simple formula.

    What do you think?

    Posted 12 years ago on Wednesday October 24, 2012 | Permalink
  2. The calculations supported are not that complex. You need a calculation plus and IF statement. How about if you did the calculation at the time of gform_pre_submission. That would allow you to store the calculated value in the entry and also use the number in the notifications. That way, with PHP, you could take the dollar value they submitted, do your 1% calculation, then use an IF statement in the PHP to round to the value you require.

    I think that would be the best way. No calculations in the form. They will not be able to see the calculated number before they submit the form. Just on the confirmation page, in the email notification, and it will be stored in the entry.

    You did not mention payment at all. If you require payment online, that will cause problems with this approach.

    Posted 12 years ago on Thursday October 25, 2012 | Permalink
  3. ameeker
    Member

    Hi guys - hope you're staying safe today and tomorrow.

    I've made some progress on this but need just a little more help piecing things together.

    Here is the function for the math that rounds the number given down to the nearest 5K.
    http://pastie.org/5133709

    Can you help me figure out what to do with it in the gform_pre_submission assuming that the field id of the original figure entered (the one being rounded) was let's say "field_1" and the field id of the number to be output (the membership figure) would be "field_2?"?

    Posted 12 years ago on Monday October 29, 2012 | Permalink
  4. ameeker
    Member

    Ok here is what I have.

    http://pastie.org/5135992

    I think this is close though. Having said that, I know this goes in my functions file, but how do I get that figure then to output in a fashion where the customer can see it on the site after they've completed the form? Is it with the dynamic population bit?

    Posted 12 years ago on Tuesday October 30, 2012 | Permalink
  5. The second pastie has a syntax error on line 3. Can you fix that to say what you mean and we'll take another look?

    Also, on line two, the function will only receive one parameter: $form. Remove $shipAmt.

    Basically though, your function will accept the user input (the field where they entered their annual shipping cost), then you will perform your calculations, and THEN you set the hidden field in your form with this calculated value. What field number are you using to hold the calculated value? And which field will contain the user's annual shipping cost? We can help with more specific code with that information.

    Looks like you've done a good job so far. We'll help you get the rest of the way.

    Posted 12 years ago on Wednesday October 31, 2012 | Permalink
  6. ameeker
    Member

    http://pastebin.com/yCJ3PYPW

    That's what worked to create the calculation.

    From here, we need to 1) display the original, pre-calculated figure, and 2) display the results of that calculation on a new page, and then 3) eventually use that amount as the figure for a payment.

    So I know that I can use the confirmation page redirect to do 1 + 2 (not sure how yet! still figuring it out).

    Basically, we're creating a flow for users where they figure out their potential savings, see a "report" of those savings, then join a membership program on that report page.

    Posted 12 years ago on Tuesday November 6, 2012 | Permalink
  7. ameeker
    Member

    Hi - I've got most of this working... the only bits I still need is how to display the original, pre-calculated figure anywhere.

    Posted 12 years ago on Tuesday November 6, 2012 | Permalink