1
0
Fork 0
feedizer-php/htdocs/libraries/Nibble-Forms/Nibble/NibbleForms/Field/Select.php

30 lines
1.1 KiB
PHP
Raw Normal View History

2015-11-13 23:51:46 +01:00
<?php
namespace Nibble\NibbleForms\Field;
class Select extends Options
{
public function __construct($label, array $attributes = array())
{
parent::__construct($label, $attributes);
}
public function returnField($form_name, $name, $value = '')
{
$field = sprintf('<select name="%2$s[%1$s]" id="%2$s_%1$s">', $name, $form_name);
foreach ($this->options as $key => $val) {
$attributes = $this->getAttributeString($val);
$field .= sprintf('<option value="%s" %s>%s</option>', $key, ((string) $key === (string) $value ? 'selected="selected"' : '') . $attributes['string'], $attributes['val']);
}
$field .= '</select>';
$class = !empty($this->error) ? 'error choice_label' : 'choice_label';
return array(
'messages' => !empty($this->custom_error) && !empty($this->error) ? $this->custom_error : $this->error,
'label' => $this->label == false ? false : sprintf('<label for="%s_%s" class="%s">%s</label>', $form_name, $name, $class, $this->label),
'field' => $field,
'html' => $this->html
);
}
}