build($label); $name = \Template::instance()->build($name); $value = \Template::instance()->build($value); $selected = \Template::instance()->build($selected); if(defined("BulmaFormHelper::$type")){ $type_const = constant("BulmaFormHelper::$type"); switch( $type_const ){ case BulmaFormHelper::H_FIELD_INPUT: return BulmaFormHelper::build_h_field_input($label, $name, $value); break; case BulmaFormHelper::H_FIELD_TEXTAREA: return BulmaFormHelper::build_h_field_textarea($label, $name, $value); break; case BulmaFormHelper::H_FIELD_SELECT: return BulmaFormHelper::build_h_field_select($label, $name, $options, $selected); break; case BulmaFormHelper::H_FIELD_SELECT_NEW: return BulmaFormHelper::build_h_field_select_new($attr); break; case BulmaFormHelper::FIELD_INPUT: return BulmaFormHelper::build_field_input($label, $name, $value, $class); break; case BulmaFormHelper::FIELD_TEXTAREA: return BulmaFormHelper::build_field_textarea($label, $name, $value, $class, $rows); break; case BulmaFormHelper::FIELD_SELECT: return BulmaFormHelper::build_field_select($attr); break; default: return '
Error: Bulma CSS Form TYPE ('.$type.') not defined.
'; break; } } else { return '
Error: Bulma CSS Form TYPE not defined.
'; } } static function build_field_input($label, $name, $value, $class, $rows=10){ $string_label = $label !== '' ? sprintf('', $label) : ''; $string = '
%1$s
'; return sprintf($string, $string_label, $name, $value, $class, $rows); } static function build_field_textarea($label, $name, $value, $class, $rows=10) { $string_label = $label !== '' ? sprintf('', $label) : ''; $string = '
%1$s
'; return sprintf($string, $string_label, $name, $value, $class,$rows); } static function build_h_field_textarea($label, $name, $value){ $string = '
'; return $string; } static function build_h_field_input($label, $name, $value){ $string = '
'; return $string; } /** * build_field_select_new * * `` * * @param mixed $attr * @return void */ static function build_field_select($attr) { $f3 = \Base::instance(); $class = $attr['class'] ?? ''; $label = $attr['label'] ?? ''; $name = $attr['name'] ?? ''; // $options_arr = $attr['options'] ?? []; $option_value = $attr['option_value'] ?? 'id'; $option_name = $attr['option_name'] ?? 'name'; $options = \Template::instance()->token($attr['options']); $selected = \Template::instance()->token($attr['selected']); // TODO: label - this could be moved into a seperate function $html_label = $label !== '' ? sprintf('', $label) : ''; $tmp_options = 'field_select('. $options.', '.$selected.', "'.$option_value.'", "'.$option_name.'"); ?>'; $html = '
%1$s
'; return sprintf($html, $html_label, $tmp_options, $name, $class); } function field_select($options, $selected, $option_value, $option_name){ $html_options = ''; foreach ($options as $option) { $value = $option[$option_value] ?? ''; $text = $option[$option_name] ?? ''; $html_selected = ((string)$value === (string)$selected) ? ' selected="selected"' : ''; $html_option = ''; $html_options .= sprintf($html_option, $value, $html_selected, $text); } echo $html_options; } static function build_h_field_select_new($attr) { $f3 = \Base::instance(); $label = $attr['label'] ?? ''; $name = $attr['name'] ?? ''; $options_arr = $attr['options'] ?? []; $optionValue = $attr['option_value'] ?? 'id'; $optionName = $attr['option_name'] ?? 'name'; $selected = $attr['selected'] ?? ''; $options = $f3->get($options_arr); $html = '
'; if (!empty($label)) { $html .= ''; } $html .= '
'; $html .= '
'; $html .= ''; $html .= '
'; return $html; } static function build_h_field_select($label, $name, $options, $selected){ $opts = json_decode(str_replace("'", '"', $options)); $opts_string = ""; foreach($opts as $k => $v){ if($v == $selected){ $selected_str = " selected"; } else { $selected_str = ""; } $opts_string .= ''.$v.''; } $string = '
'; return $string; } } \Template::instance()->extend('bulma', 'BulmaFormHelper::render');