r49201 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r49200‎ | r49201 | r49202 >
Date:10:10, 5 April 2009
Author:werdna
Status:deferred
Tags:
Comment:
Some helpful validation methods for the select-type forms
Modified paths:
  • /branches/preferences-work/phase3/includes/HTMLForm.php (modified) (history)

Diff [purge]

Index: branches/preferences-work/phase3/includes/HTMLForm.php
@@ -339,6 +339,13 @@
340340
341341 class HTMLSelectField extends HTMLFormField {
342342
 343+ function validate( $value ) {
 344+ if ( array_key_exists( $value, $this->mParams['options'] ) )
 345+ return true;
 346+ else
 347+ return 'htmlform-select-badoption';
 348+ }
 349+
343350 function getInputHTML( $value ) {
344351 $select = new XmlSelect( $this->mName, $this->mID, $value );
345352
@@ -351,6 +358,16 @@
352359 }
353360
354361 class HTMLMultiSelectField extends HTMLFormField {
 362+ function validate( $value ) {
 363+ // If all options are valid, array_intersect of the valid options and the provided
 364+ // options will return the provided options.
 365+ $validValues = array_intersect( $value, array_keys($this->mParams['options']) );
 366+ if ( count( $validValues ) == count($value) )
 367+ return true;
 368+ else
 369+ return 'htmlform-select-badoption';
 370+ }
 371+
355372 function getInputHTML( $value ) {
356373 $html = '';
357374 foreach( $this->mParams['options'] as $key => $label ) {
@@ -375,6 +392,13 @@
376393 }
377394
378395 class HTMLRadioField extends HTMLFormField {
 396+ function validate( $value ) {
 397+ if ( array_key_exists( $value, $this->mParams['options'] ) )
 398+ return true;
 399+ else
 400+ return 'htmlform-select-badoption';
 401+ }
 402+
379403 function getInputHTML( $value ) {
380404 $html = '';
381405

Status & tagging log