callback_before_insert example

In this example try to add an empty postal code.
function example_callback_before_insert(){
 
    $crud = new grocery_CRUD();
 
    $crud->set_table('offices');
    $crud->set_subject('Office');
    $crud->required_fields('city');
    $crud->columns('city','country','phone','addressLine1','postalCode');
    $crud->callback_before_insert(function ($post_array)  {
        if (empty($post_array['postalCode'])) {
            $post_array['postalCode'] = 'Not U.S.';
        }
        return $post_array;
    });
 
    $output = $crud->render();
 
    $this->_example_output($output);
}
 
Note: The below example is an iframe so it might appeared with a scroll bar. If you like you can view the example on a new tab