Pages

Pages

Previous: Relationships Up to Contents Next: Delegate Classes

Getting Started with Xataface

Jump:

Web Lite is a simple framework for developing data-driven web applications in PHP and MySQL. This tutorial will show you how to get a dataface powered web application running in under 20 minutes.

Form Validation

Xataface allows you to add validation rules to fields using the fields.ini file

A common requirement for forms is to have some validation rules.  Here are some example validation rules:

  • The Username field is required.
  • The Username must be between 6 and 16 characters long.
  • The password must have at least one letter and one digit.
  • The Email field must contain a valid email address.

There is no end to the types of things that you will need to validate.  Xataface takes care of most of this for you with both client-side (javascript) and server-side validation.  All you have to do is define some validation rules in the fields.ini file.

Example 1: Make 'Username' a required field

[Username]
validators:required = true
validators:required:message = "Username is required"

Placing the above inside the fields.ini file will cause the Username field to be a required field.

Example 2: Username must be between 6 and 16 characters long

For this rule we will use a regular expression.

[Username]
validators:regex = "/^.{6,16}$/"
validators:regex:message = "Username must be between 6 and 16 characters long"

Example 3: Email field must contain a valid email address

[Email]
validators:email = true
validators:email:message = "Email must contain a valid email address"

Available validation rules

Xataface uses the PEAR library HTML_Quickform for validation, so any of the validators available in this package will be available in Xataface.  Some of the available validation rules include:

  • required
  • maxlength
  • rangelength
  • regex
  • email
  • emailorblank
  • lettersonly
  • alphanumeric
  • numeric
  • nopunctuation
  • nonzero

Default validation rules

There are certain validation rules that are automatically applied to fields of with certain characteristics.  For example, any field designated NOT NULL in the SQL table definition will automatically be a 'required' field.  At the time of this writing, that is the only 'default' validation rule applied, but more may be added in the future if their addition makes sense.

 

 

 

 

Previous: Relationships Up to Contents Next: Delegate Classes
blog comments powered by Disqus
Powered by Xataface
(c) 2005-2024 All rights reserved