public static function formField($name, $array, $value = false, $element = false, $field_name = false) { if (!@$array || !is_array($array) || !@$name) { return false; } if (isset($array['content'])) { return $array['content']; } #Helper::d($array); return; $return = ''; #$name = $array['name']; #if ($name_group != '') # $name = $name_group . '[' . $name . ']'; #var_dump($value); $value = isset($value) ? $value : @$array['default']; #echo (int)(isset($value) && $value !== NULL); #var_dump($value); if (is_object($element) && $element->id) { $element = $element->extract(); } /* foreach ($element['fields'] as $f => $field) { $element['fields'][$field['key']] = $field; unset($element['fields'][$f]); } */ #Helper::ta($element); if (@is_callable($array['value_modifier'])) { $value = $array['value_modifier']($value, $element); } #Helper::d($value); $others = array(); $others_array = array(); if (@count($array['others'])) { foreach ($array['others'] as $o => $other) { $others[] = $o . '="' . $other . '"'; $others_array[$o] = $other; } } $others = ' ' . implode(' ', $others); #$others_string = self::arrayToAttributes($others_array); #Helper::dd($others_array); switch (@$array['type']) { case 'text': $return = Form::text($name, $value, $others_array); break; case 'textarea': $return = Form::textarea($name, $value, $others_array); break; case 'textarea_redactor': $others_array['class'] = trim(@$others_array['class'] . ' redactor redactor_150'); $return = Form::textarea($name, $value, $others_array); break; case 'image': $return = ExtForm::image($name, $value, @$array['params']); break; case 'gallery': $return = ExtForm::gallery($name, $value, @$array['params']); break; case 'date': $others_array['class'] = trim(@$others_array['class'] . ' datepicker'); $return = Form::text($name, $value, $others_array); break; case 'upload': $others_array['class'] = trim(@$others_array['class'] . ' file_upload'); #Helper::dd($others_array); $return = ExtForm::upload($name, $value, $others_array); break; case 'video': $return = ExtForm::video($name, $value, $others_array); break; case 'select': #Helper::d($array); #Helper::dd($value); $values = $array['values']; $return = Form::select($name, $values, $value, $others_array); break; case 'select-multiple': $values = $array['values']; $others_array['class'] = trim(@$others_array['class'] . ' select-multiple select2'); $others_array['multiple'] = 'multiple'; $return = Form::select($name . '[]', $values, $value, $others_array); break; case 'checkbox': #Helper::d($name); #Helper::d($others_array); #Helper::d($array['title']); #Helper::d($array); #var_dump($value); #return; #Helper::d($array); #Helper::ta($element); $v = $value; #$v = @$element->{$field_name}; return '<label class="checkbox">' . Form::checkbox($name, 1, $v, $others_array) . '<i></i>' . '<span>' . $array['title'] . '</span>' . '</label>'; break; case 'checkboxes': $return = ''; $style = ''; $col_num = 12; if ($array['columns'] == 2) { $style = ' col col-6'; } elseif ($array['columns'] == 3) { $style = ' col col-4'; } foreach ($array['values'] as $key => $val) { $checked = is_array($value) && isset($value[$key]); $el = '<label class="checkbox' . $style . '">' . "\n" . Form::checkbox($name . '[]', $key, $checked, $others_array) . "\n" . '<i></i>' . "\n" . '<span>' . $val . '</span>' . "\n" . '</label>' . "\n\n"; $return .= $el; } $return = '<div class="clearfix">' . $return . '</div>'; #Helper::d(htmlspecialchars($return)); break; case 'hidden': $return = Form::hidden($name, $value, $others_array); break; case 'textline': if (!$value) { if (@$array['default']) { $return = $array['default'] . Form::hidden($name, $value); } else { $return = Form::text($name, null, $others_array); } } else { $return = (isset($array['view_text']) ? $array['view_text'] : $value) . Form::hidden($name, $value); } break; case 'custom': $return = @$array['content']; break; } return $return; }