Re: QuickForm validation

From: Date: Tue, 13 Apr 2004 11:01:06 +0000
Subject: Re: QuickForm validation
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-11816@lists.php.net to get a copy of this message
_________________________ "Sagi Bashari" <sagi@boom.org.il> wrote in message news:407BBD64.5060206@boom.org.il... > Hello, > > 1. Is it possible to make the select element automatically validate that > a value is part of $options? > You must create your own validation rule: function qf_in_array( $submitValue, $okValues ) { /* Validates that passed value belongs to a parameter array $okValues Two cases: 1. "Single" element: $submitValue = scalar, okValue = simple array 2. "Array" element (eg hierselect): $submitValue = array, okValue = array of simple arrays */ if ( is_array( $submitValue ) ) { foreach ( $submitValue as $key => $value ) { if ( !in_array( $value, $okValues[$key] ) ) { return FALSE ; } } return TRUE ; } else { return in_array( $submitValue, $okValues ) ; } } // Register "in array" rule $this->registerRule( "ok_values", "callback", "qf_in_array" ) ; $this->addRule( "xx", "Correct type please", "ok_values", array_keys( $options ) ) ; I use such a rule so often, I deplore it is not in the main distribution. > 2. How can I validate if a value is in a specific numrange? I've seen > such class in the rules-custom.php example but shouldn't such a basic > validation be part of the normal package? I concur. HTH Ignatius

« previous php.pear.general (#11816) next »