Calculation in a form

4 posts by 2 authors in: Forums > CMS Builder
Last Post: November 30, 2011   (RSS)

Hi all,


I did some Googling and I think I'm more confused then when I started. So, before I embark on this journey, I thought I’d ask for some input from you folks.

Has anyone had success with a straight forward approach to complex calculations inside a form using CMSB?

Here’s what I’m trying to do.

A customer has a number of standard sizes (in inches) for the printing of images. (I’m including these in “Standard Width” and “Standard Height” options fields in my form.

There’s also a Price Per Square Foot of print media (in US dollars and cents) that are in another options field.

There are also times when other services get added to the price, like special mounting which add various values to the price per square foot. These would be selected from another options field.

On submitting the form I’d like the Total Print Price to appear in another field.

So the formula would be something like:

((Standard Width - inches X Standard Height - inches )/144) X (Price Per Square Foot + optional factor for mounting) = Total Print Price (formatted for US dollars and cents)

Any ideas appreciated. (Even another approach)

Thanks,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Calculation in a form

By Jason - November 28, 2011

Hi Jerry,

If the calculation is made after submission of the form, you could do your calculation in a plugin that uses the record_postsave hook.

You can have a "total_print_price" field in your section. It would be good to set this as an admin/system field, with a description that this is an auto-calculated field that should not be changed.

In your plugin function, you can calculate your total price based on your formula, and then update the record, setting total_print_price to your calculated value.

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Calculation in a form

Thanks Jason,

It's going to take me a while to get my head around this one . If you have any examples that I could follow and build on that would help a lot.

Thanks,

Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php