Support offsets in prefix searching
[mediawiki.git] / includes / htmlform / HTMLFormField.php
blob4cf23942ff66805c7506269fd249362434bc3eec
1 <?php
3 /**
4 * The parent class to generate form fields. Any field type should
5 * be a subclass of this.
6 */
7 abstract class HTMLFormField {
8 public $mParams;
10 protected $mValidationCallback;
11 protected $mFilterCallback;
12 protected $mName;
13 protected $mLabel; # String label. Set on construction
14 protected $mID;
15 protected $mClass = '';
16 protected $mHelpClass = false;
17 protected $mDefault;
18 protected $mOptions = false;
19 protected $mOptionsLabelsNotFromMessage = false;
20 protected $mHideIf = null;
22 /**
23 * @var bool If true will generate an empty div element with no label
24 * @since 1.22
26 protected $mShowEmptyLabels = true;
28 /**
29 * @var HTMLForm
31 public $mParent;
33 /**
34 * This function must be implemented to return the HTML to generate
35 * the input object itself. It should not implement the surrounding
36 * table cells/rows, or labels/help messages.
38 * @param string $value The value to set the input to; eg a default
39 * text for a text input.
41 * @return string Valid HTML.
43 abstract function getInputHTML( $value );
45 /**
46 * Get a translated interface message
48 * This is a wrapper around $this->mParent->msg() if $this->mParent is set
49 * and wfMessage() otherwise.
51 * Parameters are the same as wfMessage().
53 * @return Message
55 function msg() {
56 $args = func_get_args();
58 if ( $this->mParent ) {
59 $callback = array( $this->mParent, 'msg' );
60 } else {
61 $callback = 'wfMessage';
64 return call_user_func_array( $callback, $args );
68 /**
69 * Fetch a field value from $alldata for the closest field matching a given
70 * name.
72 * This is complex because it needs to handle array fields like the user
73 * would expect. The general algorithm is to look for $name as a sibling
74 * of $this, then a sibling of $this's parent, and so on. Keeping in mind
75 * that $name itself might be referencing an array.
77 * @param array $alldata
78 * @param string $name
79 * @return string
81 protected function getNearestFieldByName( $alldata, $name ) {
82 $tmp = $this->mName;
83 $thisKeys = array();
84 while ( preg_match( '/^(.+)\[([^\]]+)\]$/', $tmp, $m ) ) {
85 array_unshift( $thisKeys, $m[2] );
86 $tmp = $m[1];
88 if ( substr( $tmp, 0, 2 ) == 'wp' &&
89 !isset( $alldata[$tmp] ) &&
90 isset( $alldata[substr( $tmp, 2 )] )
91 ) {
92 // Adjust for name mangling.
93 $tmp = substr( $tmp, 2 );
95 array_unshift( $thisKeys, $tmp );
97 $tmp = $name;
98 $nameKeys = array();
99 while ( preg_match( '/^(.+)\[([^\]]+)\]$/', $tmp, $m ) ) {
100 array_unshift( $nameKeys, $m[2] );
101 $tmp = $m[1];
103 array_unshift( $nameKeys, $tmp );
105 $testValue = '';
106 for ( $i = count( $thisKeys ) - 1; $i >= 0; $i-- ) {
107 $keys = array_merge( array_slice( $thisKeys, 0, $i ), $nameKeys );
108 $data = $alldata;
109 while ( $keys ) {
110 $key = array_shift( $keys );
111 if ( !is_array( $data ) || !isset( $data[$key] ) ) {
112 continue 2;
114 $data = $data[$key];
116 $testValue = (string)$data;
117 break;
120 return $testValue;
124 * Helper function for isHidden to handle recursive data structures.
126 * @param array $alldata
127 * @param array $params
128 * @return bool
130 protected function isHiddenRecurse( array $alldata, array $params ) {
131 $origParams = $params;
132 $op = array_shift( $params );
134 try {
135 switch ( $op ) {
136 case 'AND':
137 foreach ( $params as $i => $p ) {
138 if ( !is_array( $p ) ) {
139 throw new MWException(
140 "Expected array, found " . gettype( $p ) . " at index $i"
143 if ( !$this->isHiddenRecurse( $alldata, $p ) ) {
144 return false;
147 return true;
149 case 'OR':
150 foreach ( $params as $p ) {
151 if ( !is_array( $p ) ) {
152 throw new MWException(
153 "Expected array, found " . gettype( $p ) . " at index $i"
156 if ( $this->isHiddenRecurse( $alldata, $p ) ) {
157 return true;
160 return false;
162 case 'NAND':
163 foreach ( $params as $i => $p ) {
164 if ( !is_array( $p ) ) {
165 throw new MWException(
166 "Expected array, found " . gettype( $p ) . " at index $i"
169 if ( !$this->isHiddenRecurse( $alldata, $p ) ) {
170 return true;
173 return false;
175 case 'NOR':
176 foreach ( $params as $p ) {
177 if ( !is_array( $p ) ) {
178 throw new MWException(
179 "Expected array, found " . gettype( $p ) . " at index $i"
182 if ( $this->isHiddenRecurse( $alldata, $p ) ) {
183 return false;
186 return true;
188 case 'NOT':
189 if ( count( $params ) !== 1 ) {
190 throw new MWException( "NOT takes exactly one parameter" );
192 $p = $params[0];
193 if ( !is_array( $p ) ) {
194 throw new MWException(
195 "Expected array, found " . gettype( $p ) . " at index 0"
198 return !$this->isHiddenRecurse( $alldata, $p );
200 case '===':
201 case '!==':
202 if ( count( $params ) !== 2 ) {
203 throw new MWException( "$op takes exactly two parameters" );
205 list( $field, $value ) = $params;
206 if ( !is_string( $field ) || !is_string( $value ) ) {
207 throw new MWException( "Parameters for $op must be strings" );
209 $testValue = $this->getNearestFieldByName( $alldata, $field );
210 switch ( $op ) {
211 case '===':
212 return ( $value === $testValue );
213 case '!==':
214 return ( $value !== $testValue );
217 default:
218 throw new MWException( "Unknown operation" );
220 } catch ( MWException $ex ) {
221 throw new MWException(
222 "Invalid hide-if specification for $this->mName: " .
223 $ex->getMessage() . " in " . var_export( $origParams, true ),
224 0, $ex
230 * Test whether this field is supposed to be hidden, based on the values of
231 * the other form fields.
233 * @since 1.23
234 * @param array $alldata The data collected from the form
235 * @return bool
237 function isHidden( $alldata ) {
238 if ( !$this->mHideIf ) {
239 return false;
242 return $this->isHiddenRecurse( $alldata, $this->mHideIf );
246 * Override this function if the control can somehow trigger a form
247 * submission that shouldn't actually submit the HTMLForm.
249 * @since 1.23
250 * @param string|array $value The value the field was submitted with
251 * @param array $alldata The data collected from the form
253 * @return bool True to cancel the submission
255 function cancelSubmit( $value, $alldata ) {
256 return false;
260 * Override this function to add specific validation checks on the
261 * field input. Don't forget to call parent::validate() to ensure
262 * that the user-defined callback mValidationCallback is still run
264 * @param string|array $value The value the field was submitted with
265 * @param array $alldata The data collected from the form
267 * @return bool|string True on success, or String error to display, or
268 * false to fail validation without displaying an error.
270 function validate( $value, $alldata ) {
271 if ( $this->isHidden( $alldata ) ) {
272 return true;
275 if ( isset( $this->mParams['required'] )
276 && $this->mParams['required'] !== false
277 && $value === ''
279 return $this->msg( 'htmlform-required' )->parse();
282 if ( isset( $this->mValidationCallback ) ) {
283 return call_user_func( $this->mValidationCallback, $value, $alldata, $this->mParent );
286 return true;
289 function filter( $value, $alldata ) {
290 if ( isset( $this->mFilterCallback ) ) {
291 $value = call_user_func( $this->mFilterCallback, $value, $alldata, $this->mParent );
294 return $value;
298 * Should this field have a label, or is there no input element with the
299 * appropriate id for the label to point to?
301 * @return bool True to output a label, false to suppress
303 protected function needsLabel() {
304 return true;
308 * Tell the field whether to generate a separate label element if its label
309 * is blank.
311 * @since 1.22
313 * @param bool $show Set to false to not generate a label.
314 * @return void
316 public function setShowEmptyLabel( $show ) {
317 $this->mShowEmptyLabels = $show;
321 * Get the value that this input has been set to from a posted form,
322 * or the input's default value if it has not been set.
324 * @param WebRequest $request
325 * @return string The value
327 function loadDataFromRequest( $request ) {
328 if ( $request->getCheck( $this->mName ) ) {
329 return $request->getText( $this->mName );
330 } else {
331 return $this->getDefault();
336 * Initialise the object
338 * @param array $params Associative Array. See HTMLForm doc for syntax.
340 * @since 1.22 The 'label' attribute no longer accepts raw HTML, use 'label-raw' instead
341 * @throws MWException
343 function __construct( $params ) {
344 $this->mParams = $params;
346 # Generate the label from a message, if possible
347 if ( isset( $params['label-message'] ) ) {
348 $msgInfo = $params['label-message'];
350 if ( is_array( $msgInfo ) ) {
351 $msg = array_shift( $msgInfo );
352 } else {
353 $msg = $msgInfo;
354 $msgInfo = array();
357 $this->mLabel = wfMessage( $msg, $msgInfo )->parse();
358 } elseif ( isset( $params['label'] ) ) {
359 if ( $params['label'] === '&#160;' ) {
360 // Apparently some things set &nbsp directly and in an odd format
361 $this->mLabel = '&#160;';
362 } else {
363 $this->mLabel = htmlspecialchars( $params['label'] );
365 } elseif ( isset( $params['label-raw'] ) ) {
366 $this->mLabel = $params['label-raw'];
369 $this->mName = "wp{$params['fieldname']}";
370 if ( isset( $params['name'] ) ) {
371 $this->mName = $params['name'];
374 $validName = Sanitizer::escapeId( $this->mName );
375 $validName = str_replace( array( '.5B', '.5D' ), array( '[', ']' ), $validName );
376 if ( $this->mName != $validName && !isset( $params['nodata'] ) ) {
377 throw new MWException( "Invalid name '{$this->mName}' passed to " . __METHOD__ );
380 $this->mID = "mw-input-{$this->mName}";
382 if ( isset( $params['default'] ) ) {
383 $this->mDefault = $params['default'];
386 if ( isset( $params['id'] ) ) {
387 $id = $params['id'];
388 $validId = Sanitizer::escapeId( $id );
390 if ( $id != $validId ) {
391 throw new MWException( "Invalid id '$id' passed to " . __METHOD__ );
394 $this->mID = $id;
397 if ( isset( $params['cssclass'] ) ) {
398 $this->mClass = $params['cssclass'];
401 if ( isset( $params['csshelpclass'] ) ) {
402 $this->mHelpClass = $params['csshelpclass'];
405 if ( isset( $params['validation-callback'] ) ) {
406 $this->mValidationCallback = $params['validation-callback'];
409 if ( isset( $params['filter-callback'] ) ) {
410 $this->mFilterCallback = $params['filter-callback'];
413 if ( isset( $params['flatlist'] ) ) {
414 $this->mClass .= ' mw-htmlform-flatlist';
417 if ( isset( $params['hidelabel'] ) ) {
418 $this->mShowEmptyLabels = false;
421 if ( isset( $params['hide-if'] ) ) {
422 $this->mHideIf = $params['hide-if'];
427 * Get the complete table row for the input, including help text,
428 * labels, and whatever.
430 * @param string $value The value to set the input to.
432 * @return string Complete HTML table row.
434 function getTableRow( $value ) {
435 list( $errors, $errorClass ) = $this->getErrorsAndErrorClass( $value );
436 $inputHtml = $this->getInputHTML( $value );
437 $fieldType = get_class( $this );
438 $helptext = $this->getHelpTextHtmlTable( $this->getHelpText() );
439 $cellAttributes = array();
440 $rowAttributes = array();
441 $rowClasses = '';
443 if ( !empty( $this->mParams['vertical-label'] ) ) {
444 $cellAttributes['colspan'] = 2;
445 $verticalLabel = true;
446 } else {
447 $verticalLabel = false;
450 $label = $this->getLabelHtml( $cellAttributes );
452 $field = Html::rawElement(
453 'td',
454 array( 'class' => 'mw-input' ) + $cellAttributes,
455 $inputHtml . "\n$errors"
458 if ( $this->mHideIf ) {
459 $rowAttributes['data-hide-if'] = FormatJson::encode( $this->mHideIf );
460 $rowClasses .= ' mw-htmlform-hide-if';
463 if ( $verticalLabel ) {
464 $html = Html::rawElement( 'tr',
465 $rowAttributes + array( 'class' => "mw-htmlform-vertical-label $rowClasses" ), $label );
466 $html .= Html::rawElement( 'tr',
467 $rowAttributes + array(
468 'class' => "mw-htmlform-field-$fieldType {$this->mClass} $errorClass $rowClasses"
470 $field );
471 } else {
472 $html =
473 Html::rawElement( 'tr',
474 $rowAttributes + array(
475 'class' => "mw-htmlform-field-$fieldType {$this->mClass} $errorClass $rowClasses"
477 $label . $field );
480 return $html . $helptext;
484 * Get the complete div for the input, including help text,
485 * labels, and whatever.
486 * @since 1.20
488 * @param string $value The value to set the input to.
490 * @return string Complete HTML table row.
492 public function getDiv( $value ) {
493 list( $errors, $errorClass ) = $this->getErrorsAndErrorClass( $value );
494 $inputHtml = $this->getInputHTML( $value );
495 $fieldType = get_class( $this );
496 $helptext = $this->getHelpTextHtmlDiv( $this->getHelpText() );
497 $cellAttributes = array();
498 $label = $this->getLabelHtml( $cellAttributes );
500 $outerDivClass = array(
501 'mw-input',
502 'mw-htmlform-nolabel' => ( $label === '' )
505 $field = Html::rawElement(
506 'div',
507 array( 'class' => $outerDivClass ) + $cellAttributes,
508 $inputHtml . "\n$errors"
510 $divCssClasses = array( "mw-htmlform-field-$fieldType", $this->mClass, $errorClass );
511 if ( $this->mParent->isVForm() ) {
512 $divCssClasses[] = 'mw-ui-vform-field';
515 $wrapperAttributes = array(
516 'class' => $divCssClasses,
518 if ( $this->mHideIf ) {
519 $wrapperAttributes['data-hide-if'] = FormatJson::encode( $this->mHideIf );
520 $wrapperAttributes['class'][] = ' mw-htmlform-hide-if';
522 $html = Html::rawElement( 'div', $wrapperAttributes, $label . $field );
523 $html .= $helptext;
525 return $html;
529 * Get the complete raw fields for the input, including help text,
530 * labels, and whatever.
531 * @since 1.20
533 * @param string $value The value to set the input to.
535 * @return string Complete HTML table row.
537 public function getRaw( $value ) {
538 list( $errors, ) = $this->getErrorsAndErrorClass( $value );
539 $inputHtml = $this->getInputHTML( $value );
540 $helptext = $this->getHelpTextHtmlRaw( $this->getHelpText() );
541 $cellAttributes = array();
542 $label = $this->getLabelHtml( $cellAttributes );
544 $html = "\n$errors";
545 $html .= $label;
546 $html .= $inputHtml;
547 $html .= $helptext;
549 return $html;
553 * Generate help text HTML in table format
554 * @since 1.20
556 * @param string|null $helptext
557 * @return string
559 public function getHelpTextHtmlTable( $helptext ) {
560 if ( is_null( $helptext ) ) {
561 return '';
564 $rowAttributes = array();
565 if ( $this->mHideIf ) {
566 $rowAttributes['data-hide-if'] = FormatJson::encode( $this->mHideIf );
567 $rowAttributes['class'] = 'mw-htmlform-hide-if';
570 $tdClasses = array( 'htmlform-tip' );
571 if ( $this->mHelpClass !== false ) {
572 $tdClasses[] = $this->mHelpClass;
574 $row = Html::rawElement( 'td', array( 'colspan' => 2, 'class' => $tdClasses ), $helptext );
575 $row = Html::rawElement( 'tr', $rowAttributes, $row );
577 return $row;
581 * Generate help text HTML in div format
582 * @since 1.20
584 * @param string|null $helptext
586 * @return string
588 public function getHelpTextHtmlDiv( $helptext ) {
589 if ( is_null( $helptext ) ) {
590 return '';
593 $wrapperAttributes = array(
594 'class' => 'htmlform-tip',
596 if ( $this->mHelpClass !== false ) {
597 $wrapperAttributes['class'] .= " {$this->mHelpClass}";
599 if ( $this->mHideIf ) {
600 $wrapperAttributes['data-hide-if'] = FormatJson::encode( $this->mHideIf );
601 $wrapperAttributes['class'] .= ' mw-htmlform-hide-if';
603 $div = Html::rawElement( 'div', $wrapperAttributes, $helptext );
605 return $div;
609 * Generate help text HTML formatted for raw output
610 * @since 1.20
612 * @param string|null $helptext
613 * @return string
615 public function getHelpTextHtmlRaw( $helptext ) {
616 return $this->getHelpTextHtmlDiv( $helptext );
620 * Determine the help text to display
621 * @since 1.20
622 * @return string
624 public function getHelpText() {
625 $helptext = null;
627 if ( isset( $this->mParams['help-message'] ) ) {
628 $this->mParams['help-messages'] = array( $this->mParams['help-message'] );
631 if ( isset( $this->mParams['help-messages'] ) ) {
632 foreach ( $this->mParams['help-messages'] as $name ) {
633 $helpMessage = (array)$name;
634 $msg = $this->msg( array_shift( $helpMessage ), $helpMessage );
636 if ( $msg->exists() ) {
637 if ( is_null( $helptext ) ) {
638 $helptext = '';
639 } else {
640 $helptext .= $this->msg( 'word-separator' )->escaped(); // some space
642 $helptext .= $msg->parse(); // Append message
645 } elseif ( isset( $this->mParams['help'] ) ) {
646 $helptext = $this->mParams['help'];
649 return $helptext;
653 * Determine form errors to display and their classes
654 * @since 1.20
656 * @param string $value The value of the input
657 * @return array
659 public function getErrorsAndErrorClass( $value ) {
660 $errors = $this->validate( $value, $this->mParent->mFieldData );
662 if ( is_bool( $errors ) || !$this->mParent->wasSubmitted() ) {
663 $errors = '';
664 $errorClass = '';
665 } else {
666 $errors = self::formatErrors( $errors );
667 $errorClass = 'mw-htmlform-invalid-input';
670 return array( $errors, $errorClass );
673 function getLabel() {
674 return is_null( $this->mLabel ) ? '' : $this->mLabel;
677 function getLabelHtml( $cellAttributes = array() ) {
678 # Don't output a for= attribute for labels with no associated input.
679 # Kind of hacky here, possibly we don't want these to be <label>s at all.
680 $for = array();
682 if ( $this->needsLabel() ) {
683 $for['for'] = $this->mID;
686 $labelValue = trim( $this->getLabel() );
687 $hasLabel = false;
688 if ( $labelValue !== '&#160;' && $labelValue !== '' ) {
689 $hasLabel = true;
692 $displayFormat = $this->mParent->getDisplayFormat();
693 $html = '';
695 if ( $displayFormat === 'table' ) {
696 $html =
697 Html::rawElement( 'td',
698 array( 'class' => 'mw-label' ) + $cellAttributes,
699 Html::rawElement( 'label', $for, $labelValue ) );
700 } elseif ( $hasLabel || $this->mShowEmptyLabels ) {
701 if ( $displayFormat === 'div' ) {
702 $html =
703 Html::rawElement( 'div',
704 array( 'class' => 'mw-label' ) + $cellAttributes,
705 Html::rawElement( 'label', $for, $labelValue ) );
706 } else {
707 $html = Html::rawElement( 'label', $for, $labelValue );
711 return $html;
714 function getDefault() {
715 if ( isset( $this->mDefault ) ) {
716 return $this->mDefault;
717 } else {
718 return null;
723 * Returns the attributes required for the tooltip and accesskey.
725 * @return array Attributes
727 public function getTooltipAndAccessKey() {
728 if ( empty( $this->mParams['tooltip'] ) ) {
729 return array();
732 return Linker::tooltipAndAccesskeyAttribs( $this->mParams['tooltip'] );
736 * Returns the given attributes from the parameters
738 * @param array $list List of attributes to get
739 * @return array Attributes
741 public function getAttributes( array $list ) {
742 static $boolAttribs = array( 'disabled', 'required', 'autofocus', 'multiple', 'readonly' );
744 $ret = array();
746 foreach ( $list as $key ) {
747 if ( in_array( $key, $boolAttribs ) ) {
748 if ( !empty( $this->mParams[$key] ) ) {
749 $ret[$key] = '';
751 } elseif ( isset( $this->mParams[$key] ) ) {
752 $ret[$key] = $this->mParams[$key];
756 return $ret;
760 * Given an array of msg-key => value mappings, returns an array with keys
761 * being the message texts. It also forces values to strings.
763 * @param array $options
764 * @return array
766 private function lookupOptionsKeys( $options ) {
767 $ret = array();
768 foreach ( $options as $key => $value ) {
769 $key = $this->msg( $key )->plain();
770 $ret[$key] = is_array( $value )
771 ? $this->lookupOptionsKeys( $value )
772 : strval( $value );
774 return $ret;
778 * Recursively forces values in an array to strings, because issues arise
779 * with integer 0 as a value.
781 * @param array $array
782 * @return array
784 static function forceToStringRecursive( $array ) {
785 if ( is_array( $array ) ) {
786 return array_map( array( __CLASS__, 'forceToStringRecursive' ), $array );
787 } else {
788 return strval( $array );
793 * Fetch the array of options from the field's parameters. In order, this
794 * checks 'options-messages', 'options', then 'options-message'.
796 * @return array|null Options array
798 public function getOptions() {
799 if ( $this->mOptions === false ) {
800 if ( array_key_exists( 'options-messages', $this->mParams ) ) {
801 $this->mOptions = $this->lookupOptionsKeys( $this->mParams['options-messages'] );
802 } elseif ( array_key_exists( 'options', $this->mParams ) ) {
803 $this->mOptionsLabelsNotFromMessage = true;
804 $this->mOptions = self::forceToStringRecursive( $this->mParams['options'] );
805 } elseif ( array_key_exists( 'options-message', $this->mParams ) ) {
806 /** @todo This is copied from Xml::listDropDown(), deprecate/avoid duplication? */
807 $message = $this->msg( $this->mParams['options-message'] )->inContentLanguage()->plain();
809 $optgroup = false;
810 $this->mOptions = array();
811 foreach ( explode( "\n", $message ) as $option ) {
812 $value = trim( $option );
813 if ( $value == '' ) {
814 continue;
815 } elseif ( substr( $value, 0, 1 ) == '*' && substr( $value, 1, 1 ) != '*' ) {
816 # A new group is starting...
817 $value = trim( substr( $value, 1 ) );
818 $optgroup = $value;
819 } elseif ( substr( $value, 0, 2 ) == '**' ) {
820 # groupmember
821 $opt = trim( substr( $value, 2 ) );
822 if ( $optgroup === false ) {
823 $this->mOptions[$opt] = $opt;
824 } else {
825 $this->mOptions[$optgroup][$opt] = $opt;
827 } else {
828 # groupless reason list
829 $optgroup = false;
830 $this->mOptions[$option] = $option;
833 } else {
834 $this->mOptions = null;
838 return $this->mOptions;
842 * flatten an array of options to a single array, for instance,
843 * a set of "<options>" inside "<optgroups>".
845 * @param array $options Associative Array with values either Strings or Arrays
846 * @return array Flattened input
848 public static function flattenOptions( $options ) {
849 $flatOpts = array();
851 foreach ( $options as $value ) {
852 if ( is_array( $value ) ) {
853 $flatOpts = array_merge( $flatOpts, self::flattenOptions( $value ) );
854 } else {
855 $flatOpts[] = $value;
859 return $flatOpts;
863 * Formats one or more errors as accepted by field validation-callback.
865 * @param string|Message|array $errors Array of strings or Message instances
866 * @return string HTML
867 * @since 1.18
869 protected static function formatErrors( $errors ) {
870 if ( is_array( $errors ) && count( $errors ) === 1 ) {
871 $errors = array_shift( $errors );
874 if ( is_array( $errors ) ) {
875 $lines = array();
876 foreach ( $errors as $error ) {
877 if ( $error instanceof Message ) {
878 $lines[] = Html::rawElement( 'li', array(), $error->parse() );
879 } else {
880 $lines[] = Html::rawElement( 'li', array(), $error );
884 return Html::rawElement( 'ul', array( 'class' => 'error' ), implode( "\n", $lines ) );
885 } else {
886 if ( $errors instanceof Message ) {
887 $errors = $errors->parse();
890 return Html::rawElement( 'span', array( 'class' => 'error' ), $errors );