HTML_QuickForm::addFormRule()
HTML_QuickForm::addFormRule() -- 全体的な検証規則を追加する
概要
require_once 'HTML/QuickForm.php'; |
void HTML_QuickForm::addFormRule (mixed $rule)
説明
This should be used when you want to add a rule involving several fields or if you want to use some completely custom validation for your form.
The rule function/method should return TRUE in case of successful validation and array('element name' => 'error') when there were errors.
例外・エラー
表 40-1PEAR_Error の値
| エラーコード | エラーメッセージ | 意味 | 解決 |
|---|
| QUICKFORM_INVALID_RULE | Callback function does not exist in HTML_QuickForm::addFormRule() | callback_として存在しない関数の名前を使用しようとします。 | スペルチェックをしてください。 |
注意
since 3.1
この関数は、スタティックにコールする
ことはできません。
例
例 40-1addFormRule()の使用法
<?php
require_once ('HTML/QuickForm.php');
$form = new HTML_QuickForm();
// the function checks whether the passwords are the same
function cmpPass($fields)
{
if (strlen($fields['passwd1']) && strlen($fields['passwd2']) &&
$fields['passwd1'] != $fields['passwd2']) {
return array('passwd1' => 'Passwords are not the same');
}
return true;
}
$form->addElement('password', 'passwd1', 'Enter password');
$form->addElement('password', 'passwd2', 'Confirm password');
$form->addFormRule('cmpPass');
?>
|
|