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

29 lines
1.1 KiB
PHP

<?php
namespace Nibble\NibbleForms\Field;
use Nibble\NibbleForms\Useful;
class Radio extends Options
{
public function returnField($form_name, $name, $value = '')
{
$field = '';
foreach ($this->options as $key => $val) {
$attributes = $this->getAttributeString($val);
$field .= sprintf('<input type="radio" name="%6$s[%1$s]" id="%6$s_%3$s" value="%2$s" %4$s/>' .
'<label for="%6$s_%3$s">%5$s</label>'
, $name, $key, Useful::slugify($name) . '_' . Useful::slugify($key), ((string) $key === (string) $value ? 'checked="checked"' : '') . $attributes['string'], $attributes['val'], $form_name);
}
$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 class="%s">%s</label>', $class, $this->label),
'field' => $field,
'html' => $this->html
);
}
}