Adding the Values in Two Separate Fields
2 posts by 2 authors in: Forums > CMS Builder
Last Post: March 10, 2016 (RSS)
By mark99 - March 10, 2016
Is there any way to have CMS Builder add the numerical values from two fields together and then output the result onto the public site, ideally within the CMS and without using Javascript on the front-end of the website?
For example, if I wanted to show two totals for different aspects of a single product and then have a grand total below those.
By Damon - March 10, 2016
Hi,
You can use PHP to add the two numbers to and then display the total. The code would look like this:
Price 1: <?php echo $record['price_1']; ?><br/>
Price 2: <?php echo $record['price_2']; ?><br/>
Total: <?php echo ($record['price_1'] + $record['price_2']); ?><br />
Make sure that you set both the price fields in CMS Builder to only allow numbers and decimal in the Allowed Content, otherwise if someone enters a dollar sign, comma or any other character, there will be an error.
An alternative to get the total in a field within CMS Builder would be to get a custom plugin written to add the two fields and save to the third field on save.
Let me know if the code works for you or if you are interested in the plugin option.
Damon Edis - interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/