class ujform extends form {
public static $errors = array();
public static $lang_key = 't';
public static function open($attr = array(), $lang_key = 't', $errors = array(), $hidden = NULL)
{
is_string($attr) AND $attr = array('action' => $attr);
self::$errors = $errors;
self::$lang_key = $lang_key;
$action = $attr['action'];
unset($attr['action']);
return parent::open($action, $attr, $hidden);
}
public static function errors($title = 'Oops there was an error!')
{
if (empty(self::$errors) OR ! is_array(self::$errors))
return '';
$output = '
';
}
public static function label($text = '', $data = '', $extra = '')
{
// Do we need to call Kohana::lang()?
$text = (strpos($text, '.') === 0) ? Kohana::lang(self::$lang_key.$text) : $text;
if ( ! is_string($data))
{
isset($data['for']) AND $field_name = $data['for'];
// Use the name if we have one
isset($data['name']) AND $field_name = $data['name'];
}
else
{
$field_name = $data;
}
// Display the errors
if (isset($field_name) AND ! empty(self::$errors[$field_name]))
$text = ''.$text.' - '.Kohana::lang(self::$lang_key.'.'.$field_name.'.'.self::$errors[$field_name]).'';
return parent::label($data, $text, $extra);
}
}