We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 35756
    • 166 Posts
    Hello there!

    I'm using a multi-page FormIt-form, where the user can choose different checkboxes and radioboxes.

    Depending on which check- oder radiobox the user did choose, the choosing get's rated by a value (between "1" to "5"). This happens in the "emailTpl"-chunk.

    [[+age:is=`40`:then=`1`]]
    [[+age:is=`50`:then=`2`]]
    [[+age:is=`60`:then=`3`]]
    [[+age:is=`70`:then=`4`]]
    [[+age:is=`80`:then=`5`]]
    <br />
    
    [[+married=`yes`:then=`1`]]
    [[+married=`no`:then=`0`]]
    <br /><br />
    


    What I want to achieve is that the different values get summated/calculated to receive a total-value.


    • So I think I first need to set a new placeholder inside the "emailTpl"-chunk out of the existing placeholders/variables (like "age" and "married" in this example?
    • Then I think I need a snippet which does the calculating? Is it possible to run a snippet inside the "emailTpl"-Chunk and send the total-value back, before the mail gets sent?
    • Maybe it's better to work with a custom-hook before the email-hook?


    Any help is highly appreciated....
      • 35756
      • 166 Posts
      So I'm trying to write a hook to do the calculation part...but I already fail to get the calculating-values related to the choice the user made...

      <?php
      $age= $hook->getValue('age');
      $result = 0;
      
      if ( $age == `40` ) { $result = 100; }
      if ( $age == `50` ) { $result = 200; }
      
      $hook->setValue('output', $result ); 
      
      return true;
      


      Then I use my new created placeholder [[+output]] in my email-template-chunk, but the output is wrong?! I expected at least that if I did choose "40 years" the output would be "100", if "50 years" the output would be "200", but it keeps the value "0"?