$data = parent::clean();
if ($this->isAdd || $data['password1'] || $data['password2']) {
- if ($data['password1'] != $data['password2'])
- $this->errors['password2'][] = __('The two password fields didn\'t match.');
+ if ($data['password1'] !== $data['password2'])
+ $this->addError('password1', __('The two password fields didn\'t match.'));
}
return $data;
public $html_name = null;
public $label = null;
public $help_text = null;
- public $errors = array();
+ public $errors;
public function __construct($form, $field, $name)
{
}
$this->help_text = ($this->field->help_text) ? $this->field->help_text : '';
- if (isset($this->form->errors[$name])) {
- $this->errors = $this->form->errors[$name];
- }
+ $this->errors = $this->form->errors($name);
}
public function value()
public $initial = null;
public $data = array();
public $cleaned_data = array();
- public $errors = array();
+ private $errors = array();
public $is_bound = false;
public $label_suffix = ':';
{
if (!$field)
$field = '__all__';
+
+ if (!($error instanceof IPF_Form_Error)) {
+ if ($error instanceof \Exception)
+ $error = $this->getMessage();
+ $error = new IPF_Form_Error((string)$error);
+ }
+
\PFF\Arr::pushToKey($this->errors, $field, $error);
}
return $hidden;
}
- public function errors()
+ public function errors($field=null)
{
- return \PFF\Arr::get($this->errors, '__all__', array());
+ if (!$field)
+ $field = '__all__';
+ return \PFF\Arr::get($this->errors, $field, array());
}
public function renderErrors()
{
$commonErrors = $form->errors();
foreach ($form->hiddenFields() as $field_name)
- foreach (\PFF\Arr::get($form->errors, $field_name, array()) as $error)
+ foreach ($form->errors($field_name) as $error)
$commonErrors[] = sprintf(__('(Hidden field %1$s) %2$s'), $field_name, $error);
return $commonErrors;
}