The following warnings occurred: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Warning [2] Undefined array key "avatartype" - Line: 783 - File: global.php PHP 8.1.31 (Linux)
|
[SOLVED] Pre-Parser Code Example to do maths and and Update Total Field - Printable Version +- Form Tools (https://forums.formtools.org) +-- Forum: Modules / Other (https://forums.formtools.org/forumdisplay.php?fid=8) +--- Forum: Modules (https://forums.formtools.org/forumdisplay.php?fid=16) +--- Thread: [SOLVED] Pre-Parser Code Example to do maths and and Update Total Field (/showthread.php?tid=2958) |
[SOLVED] Pre-Parser Code Example to do maths and and Update Total Field - ITZAP - Mar 16th, 2014 Hi, I am just one step away from completing a complex Form Tools project and am in desperate need of some help with code to make the Pre-Parser Module do the one final function required. The External website form (not Form Builder) accepts numbers of this and numbers of that. There is a Javascript equation running that dynamically calculates the TOTAL CUBIC METRES value from the numbers entered by the visitor. <script> e.g. : 'total_metres3=(bed_king*2.00)+(bed_queen*1.50)+(bed_single*0.62)+(bed_head*0.30)+(bed_draws*0.14)' And the 'total_metres3' value gets posted into the Form Tools database just fine ... lovely ! Using the "Submission Accounts" module, clients can log-in to the Form Tools UI later to update the numbers of items ... again, lovely ! However, the total_metres3 figure needs to be re-calculated and updated each time a record is edited inside the Form Tools interface. I was relying upon the "Pre-Parser Module" being able to do that task. However, I have tried, tried and tried entering various versions of code, without any success. ==>> Using the example Java equation above, is anybody able to help me with an example of some Pre-Parser code that will actually do the basic addition and multiplication to successfully re-calculate AND update the "total_metres3" field in the database ? I am at my wits end and really would appreciate some advice. Running Form Tools Core v2.2.6. Many thanks, Gary, I.T.ZAP RE: [SOLVED] Pre-Parser Code Example to do maths and and Update Total Field - ITZAP - Mar 19th, 2014 Never mind, I finally figured it out. When updating a submission inside the Form Tools Interface, here is the Pre-Parser Code that does the addition and multiplication, then successfully updates the "total_metres3" field in the database ... if ($_POST["form_tools_calling_function"] = "ft_update_submission") { $_POST["total_metres3"]=("{$_POST["bed_king"]}"*2) +("{$_POST["bed_queen"]}"*1.5) +("{$_POST["bed_single"]}"*0.62) +("{$_POST["bed_head"]}"*0.3) +("{$_POST["bed_draws"]}"*0.14) ; } But this will only work provided that : (1) The "total_metres3" field is in the same TAB View as ALL the other fields in the equation. and : (2) The "total_metres3" field is editable in that particular View. Click the Update button and whatever value was previously in the "total_metres3" field will be overwritten with the result of the equation. |