Login Retreive lost passwordRegister
Search

Forum Index / Feedback / Multiples validator

[ This topic is solved ]

  kreatik 21 July 08 / 22:49  
Hi,

Idea for allow multiples validator in array :

$form -> textField("Name", "name", array(_FH_NOT_EMPTY,_FH_STRING));

??

(french user, sorry for my bad anglish)

  Johan Wiegel (Admin) 22 July 08 / 07:59  
Changed at 22 July 08 / 14:31
Hi,

At this moment there is a feature which allows pipe seperated validators.
This is very a premature feature which is not tested very well.

<?php
$form 
-> textField("Name""name""_FH_NOT_EMPTY|_FH_STRING|YourOwnValidator" ); 
?>

  kreatik 22 July 08 / 14:26  
Changed at 22 July 08 / 16:08
Yes ! It's better than an array!

Small test appear ok for the moment...

Good work !

  kreatik 22 July 08 / 16:03  
Changed at 22 July 08 / 16:10
An another idea to get if a field passed the associated validator (if validator enabling for this field) :

<?php
$form
->isValidedField('myField');
?>


This function return TRUE if the field successfully passed validator, else, return FALSE.

??

  kreatik 22 July 08 / 16:11  
Changed at 22 July 08 / 16:12
you can delete...

  Johan Wiegel (Admin) 22 July 08 / 16:12  
That is exactly what a validater does.

it returns treu if valid and false or a msg when not valid.

  kreatik 22 July 08 / 16:13  
The function 'isValidedField()' exist ?

  Johan Wiegel (Admin) 22 July 08 / 16:15  
No, here is no need for that function.
Validating is done on a submit. Each validator returns true or false.

Can you explain why you think you need that function?

  kreatik 22 July 08 / 16:30  
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.

I understand?

  Johan Wiegel (Admin) 22 July 08 / 16:56  
So you want to check the validation of the field email in the validator MyValidator of the field rcmail?

  Johan Wiegel (Admin) 22 July 08 / 16:58  
Changed at 22 July 08 / 16:59
<?
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.

  kreatik 22 July 08 / 17:06  
Changed at 22 July 08 / 17:09
Yes I did eventually.

But it is a pity to have to create a new rule validator which already exists in FH ...


I'm found a bug with this code (blank page):

<?php
function myValidator($valueField){
    global 
$form;
    
    if(
in_array(1,$valueField) && empty(trim($formClient->getValue('email2')))){
        return 
false;
    }
}
?>



Good code :


<?php
function myValidator($valueField){
    global 
$form;
    
$var=trim($formClient->getValue('email2'));

    if(
in_array(1,$valueField) && empty($var)){
        return 
false;
    }
}
?>


  Johan Wiegel (Admin) 22 July 08 / 19:28  
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();
?>

  kreatik 22 July 08 / 23:49  
ok thank you !

Is :

FH_NOT_EMPTY.'|myValidator'

or :

'FH_NOT_EMPTY|myValidator'

?

  Johan Wiegel (Admin) 23 July 08 / 07:45  
FH_NOT_EMPTY.'|myValidator'

  kreatik 23 July 08 / 17:29  
Changed at 23 July 08 / 17:29
ok thank you !

  Top


powered by PHP-GLOBE   © 2004 - 2009 FormHandler. All rights reserved.   -   Open source license