Index: branches/preferences-work/phase3/includes/HTMLForm.php |
— | — | @@ -339,6 +339,13 @@ |
340 | 340 | |
341 | 341 | class HTMLSelectField extends HTMLFormField { |
342 | 342 | |
| 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 | + |
343 | 350 | function getInputHTML( $value ) { |
344 | 351 | $select = new XmlSelect( $this->mName, $this->mID, $value ); |
345 | 352 | |
— | — | @@ -351,6 +358,16 @@ |
352 | 359 | } |
353 | 360 | |
354 | 361 | 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 | + |
355 | 372 | function getInputHTML( $value ) { |
356 | 373 | $html = ''; |
357 | 374 | foreach( $this->mParams['options'] as $key => $label ) { |
— | — | @@ -375,6 +392,13 @@ |
376 | 393 | } |
377 | 394 | |
378 | 395 | 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 | + |
379 | 403 | function getInputHTML( $value ) { |
380 | 404 | $html = ''; |
381 | 405 | |