Changed at 22 July 08 / 16:34
Yes, I agree with you, but :
<?php
$form->textField('your email :','email',_FH_EMAIL);
$form->checkBox('receive by mail ?','rcmail','_FH_NOT_EMPTY|MyValidator');
?>
if email field is not filled, validator return true, it's good, but if rcmail field is checked and that email field not passed validator (FH_EMAIL) I want MyValidator return false.
<?
function MyValidator( $value )
{
global $form;
if( $form->GetValue( 'email' ) == '' )
{
return 'You should enter an email address to recieve by email';
}
else
{
// do somthing else
}
}
?>
leave the validation to the field it self, just check if its filled.
Changed at 22 July 08 / 19:31
But it is possible to reuse the validators defined in FH :)
You can use the validator class in your own function.
working example:
<?php
function myValidator( $valueField )
{
global $form;
$oValidator = new Validator();
$error = $oValidator->IsEmail( $form->getValue( 'email' ) );
if( $valueField == 'yes' )
{
if( $error != true )
{
return 'We need a valid email address';
}
}
return true;
}
$form = new FormHandler();
$form->textField('your email :','email',_FH_EMAIL);
$form->RadioButton('receive by mail ?','rcmail',array('yes','no'),FH_NOT_EMPTY.'|myValidator', false);
$form->SubmitButton();
$form->Flush();
?>