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 102 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 Product cat Actions
1 S12_1108 2001 Ferrari Enzo Classic Cars 1:12 Second Gear Diecast Turnable front wheels; steering function; detailed interior; detailed engine; opening hood; opening trunk; opening doors; and detailed chassis. http://displays2go.com.au/slir/w144-h144/images/product_images/1392593620.jpeg https://codecanyon.net/user/ddeveloper/portfolio?ref=ddeveloper 3619 95.59 207.80 0 0 2016-12-02 Fashion
2 S12_1666 1958 Setra Bus Trucks and Buses 1:12 Welly Diecast Productions Model features 30 windows, skylights & glare resistant glass, working steering system, original logos http://displays2go.com.au/slir/w144-h144/images/product_images/1369181990.jpg https://codecanyon.net/user/ddeveloper/portfolio?ref=ddeveloper 1579 77.90 136.67 0 0 2016-12-20 Electronics
3 S12_3148 1969 Corvair Monza Classic Cars 1:18 Welly Diecast Productions 1:18 scale die-cast about 10" long doors open, hood opens, trunk opens and wheels roll http://displays2go.com.au/images/product_images/1392665476.gif https://codecanyon.net/user/ddeveloper/portfolio?ref=ddeveloper 6906 89.14 151.08 0 0 2016-12-20 Electronics
4 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 0 0 2016-12-20 Electronics
5 S12_3891 1969 Ford Falcon Classic Cars 1:12 Second Gear Diecast Turnable front wheels; steering function; detailed interior; detailed engine; opening hood; opening trunk; opening doors; and detailed chassis. http://displays2go.com.au/slir/w144-h144/images/product_images/1384248587.jpg https://codecanyon.net/user/ddeveloper/portfolio?ref=ddeveloper 1049 83.05 173.02 0 0 2016-12-20 Electronics
6 S12_3990 1970 Plymouth Hemi Cuda Classic Cars 1:12 Studio M Art Models Very detailed 1970 Plymouth Cuda model in 1:12 scale. The Cuda is generally accepted as one of the fastest original muscle cars from the 1970s. This model is a reproduction of one of the orginal 652 cars built in 1970. Red color. http://displays2go.com.au/slir/w144-h144/images/product_images/1384248587.jpg https://codecanyon.net/user/ddeveloper/portfolio?ref=ddeveloper 5663 31.92 79.80 0 0 2016-12-20 Fashion
7 S12_4473 1957 Chevy Pickup Trucks and Buses 1:12 Exoto Designs 1:12 scale die-cast about 20" long Hood opens, Rubber wheels http://displays2go.com.au/slir/w144-h144/images/product_images/1384248587.jpg https://codecanyon.net/user/ddeveloper/portfolio?ref=ddeveloper 6125 55.70 118.50 0 0 2016-12-20 Fashion
8 S12_4675 1969 Dodge Charger Classic Cars 1:12 Welly Diecast Productions Detailed model of the 1969 Dodge Charger. This model includes finely detailed interior and exterior features. Painted in red and white. http://displays2go.com.au/slir/w144-h144/images/product_images/1384248587.jpg https://codecanyon.net/user/ddeveloper/portfolio?ref=ddeveloper 7323 58.73 115.16 0 0 2016-12-20 Electronics
9 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 Electronics
10 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 Electronics
# 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 Product cat Actions