public function returnField($name, $value = '') { $field = ''; foreach ($this->options as $key => $val) { $field .= sprintf('<input type="checkbox" name="%1$s[]" id="%3$s" value="%2$s" %4$s/>' . '<label for=%3$s>%5$s</label>', $name, $key, Useful::slugify($name) . '_' . Useful::slugify($key), is_array($value) && in_array((string) $key, $value) ? 'checked="checked"' : '', $val); } $class = !empty($this->error) ? ' class="error"' : ''; return array('messages' => !empty($this->custom_error) && !empty($this->error) ? $this->custom_error : $this->error, 'label' => $this->label == false ? false : sprintf('<p%s>%s</p>', $class, $this->label), 'field' => $field, 'html' => $this->html); }
/** * Add a field to the form instance * * @param string $field_name * @param string $type * @param array $attributes * @param boolean $overwrite * * @return boolean */ public function addField($field_name, $type = 'text', array $attributes = array(), $overwrite = false) { $namespace = "\\Nibble\\NibbleForms\\Field\\" . ucfirst($type); if (isset($attributes['label'])) { $label = $attributes['label']; } else { $label = ucfirst(str_replace('_', ' ', $field_name)); } $field_name = Useful::slugify($field_name, '_'); if (isset($this->fields->{$field_name}) && !$overwrite) { return false; } $this->fields->{$field_name} = new $namespace($label, $attributes); $this->fields->{$field_name}->setForm($this); return $this->fields->{$field_name}; }