1
0
Fork 0
feedizer-php/htdocs/libraries/Nibble-Forms/Nibble/NibbleForms/Field/MultipleSelect.php
2015-11-13 23:51:46 +01:00

31 lines
1.2 KiB
PHP

<?php
namespace Nibble\NibbleForms\Field;
class MultipleSelect extends MultipleOptions
{
public function __construct($label, $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" multiple="multiple">', $name, $form_name);
foreach ($this->options as $key => $val) {
$attributes = $this->getAttributeString($val);
$field .= sprintf('<option value="%s" %s>%s</option>', $key, (is_array($value) && in_array((string) $key, $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
);
}
}