Field Formula Apply formula for fields before insert/update operation (added in version 2.5)

You can apply basic formula to change value of the field before insert/update operation dynamically. It can be done using the callback function also but this function is added to provide more convenient way to do same. It also helps to set the value to NULL for empty values to help to enter data in case of database restriction for e.g. saving NULL for datetime for empty values.

  
                                    $pdocrud = new PDOCrud();
                                     // format field to 2 decimal point
                                    $pdocrud->fieldFormula("tax", "formula",array("type" =>"round","decimalpoint"=>2));
                                    // format field to 2 decimal point
                                    $pdocrud->fieldFormula("product_discount", "formula",array("type" =>"number_format","decimalpoint"=>2));
                                    // get ceil value of field
                                    $pdocrud->fieldFormula("product_price", "formula",array("type" =>"ceil"));
                                    //get floor value of field
                                    $pdocrud->fieldFormula("product_sell_price", "formula",array("type" =>"floor"));
                                    //string type - adding prefix of sku always and checking for duplicate i.e. string already have sku or not
                                    $pdocrud->fieldFormula("product_id","string",array("type" =>"prefix","str"=>"SKU_","duplicate"=>true));
                                    //make product name first letter upper case
                                    $pdocrud->fieldFormula("product_name", "string",array("type" =>"uppercase"));
                                    //setting value to NULL if empty
                                    $pdocrud->fieldFormula("added_Date", "string",array("type" =>"null"));
                                     
                                    echo $pdocrud->dbTable("products")->render();
                            

Formula based field content formatting

Products

Showing 1 to 10 of 94 entries

# Product id Product name Product line ProductScale ProductVendor Product description Product image Product url Qty available Product price Product sell price Tax Product discount Added date Actions
1 S12_3380 1968 Dodge Charger Classic Cars 1:12 Welly Diecast Productions 1:12 scale model of a 1968 Dodge Charger. Hood, doors and trunk all open to reveal highly detailed interior features. Steering wheel actually turns the front wheels. Color black http://displays2go.com.au/slir/w144-h144/images/product_images/1384248587.jpg http://demo.digitaldreamstech.com/wp-awesome-import-export-documentation 9123 75.16 117.44 1 0 2016-12-16
2 S18_1097 1940 Ford Pickup Truck Trucks and Buses 1:18 Studio M Art Models This model features soft rubber tires, working steering, rubber mud guards, authentic Ford logos, detailed undercarriage, opening doors and hood, removable split rear gate, full size spare mounted in bed, detailed interior with opening glove box http://displays2go.com.au/slir/w144-h144/images/product_images/1384248587.jpg https://codecanyon.net/user/ddeveloper/portfolio?ref=ddeveloper 2613 58.33 116.67 0 0 2016-12-20
3 S18_1129 1993 Mazda RX-7 Classic Cars 1:18 Highway 66 Mini Classics This model features, opening hood, opening doors, detailed engine, rear spoiler, opening trunk, working steering, tinted windows, baked enamel finish. Color red. http://displays2go.com.au/slir/w144-h144/images/product_images/1384248587.jpg http://demo.digitaldreamstech.com/formdoid/ 3975 83.51 141.54 0 0 2016-12-20
4 S18_1342 1937 Lincoln Berline Vintage Cars 1:18 Motor City Art Classics Features opening engine cover, doors, trunk, and fuel filler cap. Color black http://displays2go.com.au/slir/w144-h144/images/product_images/1384248587.jpg https://codecanyon.net/user/ddeveloper/portfolio?ref=ddeveloper 8693 60.62 102.74 0 0 2016-12-20
5 S18_1367 1936 Mercedes-Benz 500K Special Roadster Vintage Cars 1:18 Studio M Art Models This 1:18 scale replica is constructed of heavy die-cast metal and has all the features of the original: working doors and rumble seat, independent spring suspension, detailed interior, working steering system, and a bifold hood that reveals an engine so accurate that it even includes the wiring. All this is topped off with a baked enamel finish. Color white. http://displays2go.com.au/slir/w144-h144/images/product_images/1384248587.jpg https://codecanyon.net/user/ddeveloper/portfolio?ref=ddeveloper 8635 24.26 53.91 0 0 2016-12-20
6 S18_1589 1965 Aston Martin DB5 Classic Cars 1:18 Classic Metal Creations Die-cast model of the silver 1965 Aston Martin DB5 in silver. This model includes full wire wheels and doors that open with fully detailed passenger compartment. In 1:18 scale, this model measures approximately 10 inches/20 cm long. http://displays2go.com.au/slir/w144-h144/images/product_images/1384248587.jpg https://codecanyon.net/user/ddeveloper/portfolio?ref=ddeveloper 9042 65.96 124.44 0 0 2016-12-20
7 S18_1662 1980s Black Hawk Helicopter Planes 1:18 Red Start Diecast 1:18 scale replica of actual Army's UH-60L BLACK HAWK Helicopter. 100% hand-assembled. Features rotating rotor blades, propeller blades and rubber wheels. http://displays2go.com.au/slir/w144-h144/images/product_images/1384248587.jpg https://codecanyon.net/user/ddeveloper/portfolio?ref=ddeveloper 5330 77.27 157.69 0 0 2016-12-20
8 S18_1749 1917 Grand Touring Sedan Vintage Cars 1:18 Welly Diecast Productions This 1:18 scale replica of the 1917 Grand Touring car has all the features you would expect from museum quality reproductions: all four doors and bi-fold hood opening, detailed engine and instrument panel, chrome-look trim, and tufted upholstery, all topped off with a factory baked-enamel finish. http://displays2go.com.au/slir/w144-h144/images/product_images/1384248587.jpg https://codecanyon.net/item/pdomodel-database-abstraction-and-helper-php-class/15832775 2724 86.70 170.00 0 0 2016-12-20
9 S18_1889 1948 Porsche 356-A Roadster Classic Cars 1:18 Gearbox Collectibles This precision die-cast replica features opening doors, superb detail and craftsmanship, working steering system, opening forward compartment, opening rear trunk with removable spare, 4 wheel independent spring suspension as well as factory baked enamel finish. http://displays2go.com.au/slir/w144-h144/images/product_images/1384248587.jpg https://codecanyon.net/user/ddeveloper/portfolio?ref=ddeveloper 8826 53.90 77.00 0 0 2016-12-20
10 S18_1984 1995 Honda Civic Classic Cars 1:18 Min Lin Diecast This model features, opening hood, opening doors, detailed engine, rear spoiler, opening trunk, working steering, tinted windows, baked enamel finish. Color yellow. http://displays2go.com.au/slir/w144-h144/images/product_images/1384248587.jpg https://codecanyon.net/user/ddeveloper/portfolio?ref=ddeveloper 9772 93.89 142.25 0 0 2016-12-20
# Product id Product name Product line ProductScale ProductVendor Product description Product image Product url Qty available Product price Product sell price Tax Product discount Added date Actions