|
|
|
|
|
|
(Since version FH3-v1.2)
SetError |
SetError (
string |
$field |
string |
$error |
) |
Arguments:
Name |
Description |
$field |
The field where you want to set the error for |
$error |
The error message you want to set for the field |
Description:
With this function it is possible to set an error message for a field (the field's value will be interpretated as invalid!)
Note: If you just want to set a custom error message, please use SetErrorMessage!
Example
<?php
// include the class
include("FH3/class.FormHandler.php");
// create new formhandler object
$form = new FormHandler("myForm");
// simple textfield + submitbutton
$form -> textField ("Name", "name", FH_STRING);
$form -> submitbutton ("Save");
// set the commit after correct function
$form -> onCorrect ("doRun");
// flush the form
$form -> flush();
// the oncorrect function
function doRun( $data, &$form )
{
// is the name shorter then 3 characters ?
if( strlen( $data['name'] ) < 3 )
{
// set an error message for the name field
$form -> setError(
'name',
'Your name has to be at least 3 characters!'
);
// display the form again
return false;
}
else
{
echo "Hello! Your name is " . $data["name"];
}
}
?>
|
The result:
resizeIMGSee also: SetErrorMessage
Latest change: 05 March 10 / 08:54
Comments
|
|
|
|