Improve hidden field validation
authorBrad Jorsch <bjorsch@wikimedia.org>
Thu, 31 Jul 2014 18:04:00 +0000 (14:04 -0400)
committerBrad Jorsch <bjorsch@wikimedia.org>
Thu, 31 Jul 2014 18:04:00 +0000 (14:04 -0400)
Hidden fields are supposed to be ignored during validation; more
completely ensure this by checking in HTMLForm::trySubmit before calling
validate.

Also, more properly handle HTMLCheckFields in the isHidden check by
casting their booleans to strings.

Bug: 68132
Change-Id: I84f8239c299727b773015643048eed4684417733

includes/htmlform/HTMLForm.php
includes/htmlform/HTMLFormField.php

index 6cf8d0a..59e577b 100644 (file)
@@ -467,6 +467,9 @@ class HTMLForm extends ContextSource {
                        if ( !empty( $field->mParams['nodata'] ) ) {
                                continue;
                        }
+                       if ( $field->isHidden( $this->mFieldData ) ) {
+                               continue;
+                       }
                        if ( $field->validate(
                                        $this->mFieldData[$fieldname],
                                        $this->mFieldData )
index 7e4b15b..7db5ebc 100644 (file)
@@ -113,7 +113,7 @@ abstract class HTMLFormField {
                                }
                                $data = $data[$key];
                        }
-                       $testValue = $data;
+                       $testValue = (string)$data;
                        break;
                }