2

I have a form built with Sprout forms that has a few radio button fields, all with numeric values. I'm looking to provide the total sum of these fields to a hidden/invisible field upon submit.

Is it possible to provide the value of the radio button field directly to the Invisible Field Value using twig syntax? Or should I just go the scripting route and use jQuery to update the hidden/invisible field's value?

  • 1
    You'll need javascript since twig is only php thus it can't be executed during runtime. So you could only use a custom plugin to hook into the submit process to inject the field value or you could use Javascript (or some really really nasty twig redirects which nobody wants) – Robin Schambach Jan 3 '18 at 14:42
0

Two potential ways to address this:

  1. Setup a Sprout Fields Hidden Field and add javascript to your page (or in your form template using Template Overrides) to calculate the values and submit the calculated value with the rest of the form.

  2. Create a custom front-end field integration that is aware of the Radio Button fields that you need to process and have that field calculate and display the result of those values.

The first approach is probably the easiest approach and should work fine if you're sending your submissions via email and if it's unlikely that anybody will be editing the Radio Button fields in the CP. The second approach may be more robust if there is a chance the Radio Buttons ever get edited and the Total Field needs to get recalculated.

Side Note: The Invisible Field won't work in this use case right now as you want to calculate values based on the submitted form values. The Invisible Field lets you pass it dynamic values as the page loads but at that time the page would not have any info on the values of the Radio Buttons.

|improve this answer|||||
  • Thanks for clarifying the invisible field functionality. The first option worked well for the use case of this form. – raptureaid Jan 4 '18 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.