Calculate field based on other field value Apply simple math formula to dynamically calcualte a field (added in v 4.3)

If you want to calculate a field value based on the other field's value then you can easily do using the formFieldValue() function. You can apply basic math function e.g addition, subtraction, multiplication or division to generate the field value based on other field's value. For example, if you want to save the total field as multiplicate of qty and rate field and don't want to show this total field to user then you can easily acheive this using this function.

Please note that you need to hide that field from form that is being calculated. Also, math function can be applied to two fields only. It doesn't work with complex functions currently. We will further improve this function in next versions.

In the below example, we are dynamically calculating sale_price field based on the price field. We are adding 24 to price field to generate sale_price field.

  
                               $pdocrud = new PDOCrud();
                                $pdocrud->formRemoveFields(array("sale_price"));
                                /**
                                 * Set a value of field
                                 * @param   string   $fieldName                            field name to renamed
                                 * @param   string   $value                                value of the field
                                 * @param   bool     $fieldHidden                          Wheter that field is hidden or not
                                 * @param   string   $tablename                            Tablename = Required only when using join table field name
                                 * return   object                                         Object of class
                                 */
                                $pdocrud->formFieldValue("sale_price", "{price}+24", true);
                                //apply formula
                                $pdocrud->fieldFormula("sale_price", "expression",array("type" =>"math_expression"));
                                echo $pdocrud->dbTable("book")->render("insertform"); // call render function
                                

Deprecated: Optional parameter $op declared before required parameter $task is implicitly treated as a required parameter in /home3/openscri/public_html/masinosinaga/pdo-crud/script/classes/PDOCrud.php on line 983

Deprecated: Creation of dynamic property PDOCrud::$langData is deprecated in /home3/openscri/public_html/masinosinaga/pdo-crud/script/classes/PDOCrud.php on line 2227

Deprecated: Optional parameter $page declared before required parameter $totalrecords is implicitly treated as a required parameter in /home3/openscri/public_html/masinosinaga/pdo-crud/script/classes/PDOCrudHelper.php on line 191

Deprecated: Optional parameter $parameters declared before required parameter $data is implicitly treated as a required parameter in /home3/openscri/public_html/masinosinaga/pdo-crud/script/classes/PDOCrudTableFormat.php on line 122

Deprecated: Creation of dynamic property PDOCrud::$formFieldHide is deprecated in /home3/openscri/public_html/masinosinaga/pdo-crud/script/classes/PDOCrud.php on line 956

Deprecated: Creation of dynamic property PDOModel::$characterSet is deprecated in /home3/openscri/public_html/masinosinaga/pdo-crud/script/classes/PDOModel.php on line 119

Deprecated: strtoupper(): Passing null to parameter #1 ($string) of type string is deprecated in /home3/openscri/public_html/masinosinaga/pdo-crud/script/classes/PDOModel.php on line 1011

Deprecated: strtoupper(): Passing null to parameter #1 ($string) of type string is deprecated in /home3/openscri/public_html/masinosinaga/pdo-crud/script/classes/PDOModel.php on line 1011

Deprecated: Creation of dynamic property PDOModel::$characterSet is deprecated in /home3/openscri/public_html/masinosinaga/pdo-crud/script/classes/PDOModel.php on line 119

Deprecated: strtoupper(): Passing null to parameter #1 ($string) of type string is deprecated in /home3/openscri/public_html/masinosinaga/pdo-crud/script/classes/PDOModel.php on line 1011

Deprecated: Creation of dynamic property PDOCrud::$dataHTML is deprecated in /home3/openscri/public_html/masinosinaga/pdo-crud/script/classes/PDOCrud.php on line 2379

Deprecated: Creation of dynamic property PDOCrud::$fieldList is deprecated in /home3/openscri/public_html/masinosinaga/pdo-crud/script/classes/PDOCrud.php on line 2380

Book

Showing 1 to 1 of 1 entries

# Book id Name Author Price Sale price Actions
1 12 Angles & Demons DB 600 624
# Book id Name Author Price Sale price Actions