1792 Posts in 588 Topics by 560 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 237 Views |
-
I want to set up custom validation for my form page

18 November 2011 at 1:41pm
I have my form code like this below
function __construct($controller, $name) {
$fields = new FieldSet(
new TextField('Name', 'name', 'first','20'),
new EmailField('Email', 'Email address', '', '100'),
new TextField('Phone', 'Phone number','','20'),
);$actions = new FieldSet(new FormAction("login", "Log in"));
$validator = new RequiredFields('Name', 'Email');parent::__construct($controller, $name, $fields, $actions, $validator);
}I want to add more vilification for this form.
I want to add phone# vilification.
How and where I can add vilification code to do that and show an error message to form(view file) if there is error from phone number?thanks
-
Re: I want to set up custom validation for my form page

19 November 2011 at 12:14am
you can create and assign your own "extended" validator. This is a simple example...
class MyValidator extends RequiredFields {
function php($data) {
$bRet = parent::php($data);if (empty($data['MyField'])) {
$this->validationError('MyField','MyField is required',"required");
$bRet = false;
}return $bRet;
}
}
| 237 Views | ||
|
Page:
1
|
Go to Top |


