XCRUD – Data Validation

The need for validation of input data – you will have noticed my article stating what sets XCRUD apart, that I place a great deal of value on being able to control finitely the way the database table is displayed. However, the displayed data is only as good as the data held in the database. Therefore – it logically follows, that the quality of the data input needs to be spot on – especially if the data is going to be used to trigger system functions.

However, before we get into the XCRUD Data Validation features, the first consideration needs to be removing the scope for error, by providing choices whenever possible rather than offering the opportunity to enter free text which will be prone to errors, even if unintentional.

Pokayoke – Simple Choice Logic

Using the simple project status summary example used to show what sets XCRUD apart, you will recall we use the contents of the project_status field to control the colour of the project_status cell. Therefore – it logically follows that for this to work we need no ensure the database field contains a value which matches one of the highlight conditions. Here is a reminder of the code which shows the project_status value driving the cell colour.

$exampleoutput = Xcrud::get_instance();
$exampleoutput->table('wp_exampleoutput');
$exampleoutput->columns('customer, project, project_manager, project_status');
$exampleoutput->fields('customer, project, project_manager, project_status');
$exampleoutput->table_name('Project Status', 'View and Edit - Projects!');
$exampleoutput->label(array('customer' => 'Customer', 'project' => 'Project','project_manager' => 'Project Manager','project_status' => 'Project Status'));
$exampleoutput->unset_numbers();
$exampleoutput->unset_csv();
$exampleoutput->unset_add();
$exampleoutput->unset_view(true, 'viewable', '!=', 'yes');
$exampleoutput->unset_edit(true, 'editable', '!=', 'yes');
$exampleoutput->unset_remove(true, 'removable', '!=', 'yes');
$exampleoutput->highlight('project_status', '=', 'Not Started', 'red');
$exampleoutput->highlight('project_status', '=', 'Ready To Quote', 'orange');
$exampleoutput->highlight('project_status', '=', 'Proposal Issued', 'orange');
$exampleoutput->highlight('project_status', '=', 'Waiting PO', 'yellow');
$exampleoutput->highlight('project_status', '=', 'Work In Progress', 'yellow');
$exampleoutput->highlight('project_status', '=', 'Complete', '#8DED79');
echo $exampleoutput->render();

XCRUD has several functions to enable data input choices, the simplest is one of the change_type commands, which enables a drop-down list to be displayed – enabling the user to choose one from a pre-defined list. This line of code has been added to the table below – now select the edit button to see the drop-down in action:

$exampleoutput->change_type('project_status','select','--','Not Started,Ready To Quote,Proposal Issued,Waiting PO,Work In Progress,Complete');

You will recall that we also constructed the table below to display the button based on the value of the viewable, editable, removable fields, so we will implement in-line edit of this field to enable the project_status to be changed in the rows where the edit button is not displayed. This line of code has been added to the table below – now click the project_status cell to see it in action.

$exampleoutput->fields_inline('project_status');

In the table below we have not implemented data validation – but we have used two simple commands to implement choice of Project Status from a drop-down – which ensures the field value stored in the database matches one of the highlight conditions.

Note – we are in demo mode so no data will be changed in the database but the implementation of the drop-down can be clearly seen both in edit screen and in-line edit mode which can be used to change the Project Status on all rows.

Project Status

Customer Project Project Manager Project Status  
Apple Inc Website Build Jimmy Chooler Work In Progress View Edit Remove
Microsoft Inc Site Backup Amy Heinz Proposal Issued View Edit
Rolls-Royce PLC WordPress Install Bing Sharples Waiting PO View
Ford Motor Co SSL Cert Install William Hooper Ready To Quote View
Amazon Inc SEO Consultancy James Mac Complete View
Royal Opera House CMS Maintenance Plan Alan Allen Complete

Search

0 Comments

Leave a reply

Your email address will not be published. Required fields are marked *

*


The reCAPTCHA verification period has expired. Please reload the page.

Terms of Service | Privacy Policy | Copyright © 2025 all rights reserved

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

Log in with your credentials

Forgot your details?