Data Entry with Xataface
Written by Nikos Vaggalis   
Article Index
Data Entry with Xataface
Creating a Brand
Using the Grid Widget


Model to Operating System

As a final example we will examine another m:n relationship, that
of a Model to OS, by using the grid widget . One model can have one or more OSs installed and one OS can be installed in one or more models.

Let's make an entry for Windows Phone, Version 8.1:


We see that it was automatically assigned the id 44:

For making the ModelOS Edit screen:

windows phone 8.1 44 dataface application 2016 02 18 23.18.35
we have to add the following to the files inside the ModelOS directory:


__sql__ = "SELECT ModelOS.*,concat(OSName,' ',OSVersion) as
                                             OSName from OS,ModelOS,Model
         where ModelOS.OS_OSid=OS.OSid and
;So OS OSId does not display a number but
              instead display Windows Phone 8.10

widget:type = select
vocabulary = OSs
widget:type = select
vocabulary = Models

vocabulary = ModelOSInstalled

vocabulary = ModelOSUpgraded

vocabulary = ModelOSSupported







 __sql__ = "SELECT OSid,Concat(OSName,OSVersion) from OS"

__sql__ = "SELECT ModelId,ModelName from Model"




For making an OS grid appear in Model's Edit form,we have to add the following to the files inside the Model directory:

entries for field.ini:


'transient' means that the field/column does not exist in the Model table but comes from another table. 

entries for relationships.ini :

__sql__ = "SELECT * FROM ModelOS
                 WHERE Model_ModelId='$ModelId'"

We use the grid widget which gives us the capability of making even more complex selections:




According to the Model to OS relationship, we can even add a second OS:



More advanced functionality

That's the basic idea but additionally Xataface offers more advanced functionality and  customizations through its API. You can for example use triggers and Delegate classes to update tables that require special treatment not covered by the defaults.For example the following code is fired before and after saving a Model's record: 


class tables_Model {

function afterSave(Dataface_Record $record){
   if ( $record->valueChanged('FrequencyId') ){
     if ($record->val('FrequencyId')) {

         df_q( "INSERT INTO ModelFrequency    
             VALUES ($modelid,$frequencyid)");
             df_clear_views(); df_clear_cache();

function beforeSave(Dataface_Record $record){

   if ( $record->valueChanged('FrequencyId') ){
       df_q("delete ModelFrequency.*
             from ModelFrequency,Frequency
             where Model_ModelId='".$record->val('ModelId')."' and
                   Frequency.FrequencyId and



This is also an example of a Delegate class. A delegate class is a PHP class that defines custom behavior, functions, and fields for a table in a Xataface application. 

A table may have only one delegate class, thus there can be only one .php file per table directory, i.e Model/Model.php

(Note that to avoid SQL injections you have to always validate input and escape strings that you include in your SQL queries.)

The available triggers are:

  • beforeSave - called just before a record is saved to the database.

  • afterSave- called just after a record is saved to the database.

  • beforeInsert - called just before a record is inserted into the database.

  • afterInsert - called just after a record is inserted into the database.

  • beforeUpdate - called just before an existing record is updated in the database.

  • afterUpdate - called just after an existing record is updated in the database 

Other examples of what you can do:

  • Check whether the user is logged in : Dataface_AuthenticationTool::getInstance()->isLoggedIn();

  • have custom fields,called 'grafted',which can be attached to a table as virtual fields and subsequently used for grouping values etc

  • export data into pdf or xml

  • use Javascript and CSS

  • a wide variety of widgets to choose from : autocomplete,calendar,datepicker,
                             depselect,grid,file,password etc

and much more through the exposed API


Summing up, Xataface is a feature rich framework that can be further extended and customized, easing the tedious but crucial task of data entry. Give it a try and make a gift to your data entry personnel;they'll love it!

(You can download the files used in this tutorial from this Google Drive link) 


More Information


Xataface Getting started

Xataface API

Smart Device Seeker

Related Articles

MySQL Workbench 6.0 Released

A Generic SQL Performance Test Harness

Full Text Database Indexing with dtSearch

Linq to ADO - using the TableAdapter


To be informed about new articles on I Programmer, sign up for our weekly newsletter,subscribe to the RSS feed and follow us on, Twitter, FacebookGoogle+ or Linkedin



Turn PostgreSQL Into A Vector Store

pg_vector is an extension for PostgreSQL that renders it a viable alternative to specialized vector stores used in LLMs. We show you how to use it and report on the latest, faster incarnatio [ ... ]

Model Your APIs With AWS Smithy

Smithy is an open source project by AWS with which you can model your APIs, generate code and documentation for clients and servers, as well as other artifacts, in many programming languages.

More News





or email your comment to: