Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 2.3.2

Request #2746 "in array" element rule
Submitted: 2004-11-13 09:00 UTC
From: ignatius dot reilly at free dot fr Assigned:
Status: Wont fix Package: HTML_QuickForm2
PHP Version: Irrelevant OS: irrelevant
Roadmaps: 0.1.0    
Subscription  
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes. If this is not your bug, you can add a comment by following this link. If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
2007-04-05 21:27 UTC
Package:
Bug Type:
Summary:
From: ignatius dot reilly at free dot fr
New email:
PHP Version: Package Version: OS:

 

 [2004-11-13 09:00 UTC] ignatius dot reilly at free dot fr
Description: ------------ The one element rule I use the most is a rule checking that the passed value is in an array. It is so useful I think it should make it into the system-provided rules. It applies to all "keyed" elements: - radio - checkboxes - select Reproduce code: --------------- // Register "in array" rule $this->registerRule( "ok_values", "callback", "qf_in_array" ) ; // Country $values = list_countries() ; $this->addElement( "select", "country", "Select country", $values ) ; $this->addRule( "country", "Please select a valid country", "ok_values", array_keys( $values ) ) ; // --------------------- 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 ) ; } }

Comments

 [2004-11-13 10:42 UTC] bmansion at mamasam dot com
I have a rule object reeady for that, it is called HTML_QuickForm_Rule_Enum. I don't think client validation is worthwile for this rule as if someone starts to change what the radios can submit, he can obviously also change the javascript.
 [2004-11-13 10:58 UTC] ignatius dot reilly at free dot fr
I agree: - pointless to do client validation - easy to implement oneself My point was that this rule generally is so useful that is seems to me worth including in the next QF version as a "built-in" validation rule. I know you are generally (rightly) skeptical of such requests, but consider...
 [2005-07-02 06:55 UTC] jausions
Then it would be good to have QuickForm_Rule_Enum showing up somewhere in the documentation... -Philippe
 [2006-06-08 13:17 UTC] avb (Alexey Borzov)
Moving feature requests to HTML_QuickForm2.
 [2006-10-20 22:28 UTC] avb (Alexey Borzov)
This rule won't be needed in QuickForm2: values of selects, checkboxes and radios will pass a sort of intrinsic validation, confirming that the value could possibly originate from this control. Validation rules will be applied to "clean" values after this intrinsic validation.