database validation sql query results minimum rows minrows maximum rows maxrows
database validation
Database validation is a powerful validation type: creating a login form simply becomes a Clonefish form with a database validation included.
There are two ways to validate:
- use
field
andvalue
settings to validate against a value returned by a query - use
minrows
and/ormaxrows
to examine the number of rows returned by a query
In the query you can use the <FORM.fieldname>
placeholders to represent values from the form. Do not use quotes around the placeholders as Clonefish takes care of proper quoting through its database wrappers.
Using the condition
parameter you can deffine the relation between settings: by default it's set to 'and
', this way each of minrows
, maxrows
and value
conditions (if used) must be valid to have the element validated. Accordingly, 'or
' is used when any of these settings may validate the element by itself.
<?php
$config = Array(
'element' => Array(
'type' => 'inputFile',
// ...further element settings here...
'validation' => Array(
Array(
'type' => 'database',
'sql' =>
"SELECT count(*) AS counter FROM users " .
"WHERE login= <FORM.login> AND password = <FORM.password>",
'minrows' => 0,
'maxrows' => 0,
'field' => 'counter',
'value' => 1,
'condition' => 'and | or', // default: 'and'
'help' => 'Help message value for this validator only',
'helpmaxrows' => 'Help message when number of rows > maxrows',
'helpminrows' => 'Help message when number of rows < minrows',
'helpvalue' => 'Help message when value <> query field value',
)
)
)
);
?>
Live examples:
form validation for developers!
clonefish is a proven, mature form generator class that helps PHP developers to create, validate and process secure, flexible and easy-to-maintain formslearn more