Chronoforms 7 and calculations within a form

sem 09 Sep, 2022
Hi - looking at doing a new form very quickly that's a simple catering order form - a number of text fields, user enters quantity required for each. Each item will have a unit price which must be multiplied by the quantity and then a total shown at the end of the form before it's submitted as an email to a couple of people.

Question is, is this quick and easy to do in CF? I've just looked at RS Forms Pro and there are calculations available in that but I wanted to know if I can keep to using CF as for all the other forms on the system.

sem
Colnem 10 Sep, 2022
Hi

Yes, it's easy, using PHP Element... if you know basic PHP language!
sem 12 Sep, 2022
Thanks Colnem -

So would I be using php within an HTML element in the form, having an event trigger to reload the form when an input is entered or using a PHP action on the actions editor and calling it that way?

sem
Colnem 12 Sep, 2022
First, in the submit page, insert a Message in Action to see datas of your form.
Then you have to insert a PHP element in action of the submit page to calculate what do you want.
sem 12 Sep, 2022
Got it sorted in the end. Used php action and working well. Thanks for the pointers.
sem 13 Sep, 2022
Related question -

Was doing it as a single page form with a bunch of quantity fields for items - the unit prices are hidden fields to make it easy to alter. There is a php action (called total) that grabs the quantity fields and unit prices, multiplies them up and adds the total and returns this as {var:total}. I had a submit button under the form to "calculate totals" when the user filled in the fields. This refreshes the page so to execute the PHP action. The total is then shown via an HTML element and added to a hidden field for when the form is sent via email. All looked good but...

Obviously it's possible for someone to enter values for quantity, click "calculate" and then change the quantities and submit the form - the total value isn't recalculated when the form is submitted.

So I thought I'd use a multipage form - add a second page (Confirmation), change the "calculate" submit button to something like "continue" and move the php action to the second page. This works but two things crop up:

1. The quantity fields aren't required but they must be an integer - on the single page form I could leave them blank but on the multipage, I couldn't continue to confirmation until I'd put a 0 in the empty fields. Is there a way around this?

2. The total on the second page is correct the first time you enter a quantity field but if you go back (I used another submit button back to the first page to allow people to make changes), it doesn't seem to take values entered when the first page is reloaded.

I must be doing something stupid. A single page form seems clearer but I would need to rely on the user to click the recalculate totals button. Any thoughts?

sem
sem 13 Sep, 2022
Answer
Hmm - looks like caching problems - so cleared Chronoforms cache and use an incognito window in the browser. Also followed the CF7 Video tutorial on multipage forms and rather than the back button being set to submit form to the first page to make changes, I used its link behaviour. Seems to be working ok now. If I find anything else I'll add it here or close the topic if it works when complete.

Re point 1 above, setting a default value of 0 for each quantity works fine once caches are cleared. As a proof test, I open the form in a Chrome incognito window and close afterwards.

sem
You need to login to be able to post a reply.

VPS & Email Hosting 20% discount
hostinger