'; } /** * Rendert ein Zahlenfeld mit Buttons zum verstellen * * @param string $name * @param string $label * @param string $value * @return string */ function form_spinner($name, $label, $value) { $id = 'spinner-' . $name; $value = htmlspecialchars((string)$value); return form_element($label, '
', $id); } /** * Render a bootstrap datepicker * * @param string $name Name of the parameter * @param string $label Label * @param int|Carbon $value Unix Timestamp * @param string $start_date Earliest possible date * @param string $end_date * @return string HTML */ function form_date($name, $label, $value, $start_date = '', $end_date = '') { $dom_id = $name . '-date'; $value = ($value instanceof Carbon) ? $value->getTimestamp() : $value; $value = is_numeric($value) ? date('Y-m-d', $value) : ''; $start_date = is_numeric($start_date) ? date('Y-m-d', $start_date) : ''; $end_date = is_numeric($end_date) ? date('Y-m-d', $end_date) : ''; return form_element( $label, '', $dom_id ); } /** * Render a bootstrap datepicker * * @param string $name Name of the parameter * @param string $label * @param mixed $value * * @return string HTML */ function form_datetime(string $name, string $label, $value) { $dom_id = $name . '-datetime'; if ($value) { $value = ($value instanceof Carbon) ? $value : Carbon::createFromTimestamp($value); } return form_element($label, sprintf(' ', $dom_id, $name, htmlspecialchars($value ? $value->format('Y-m-d H:i') : '')), $dom_id); } /** * Rendert eine Liste von Checkboxen für ein Formular * * @param string $name Die Namen der Checkboxen werden aus name_key gebildet * @param string $label Die Beschriftung der Liste * @param array $items Array mit den einzelnen Checkboxen * @param array $selected Array mit den Keys, die ausgewählt sind * @return string */ function form_checkboxes($name, $label, $items, $selected) { $html = form_element($label, ''); foreach ($items as $key => $item) { $html .= form_checkbox($name . '_' . $key, $item, in_array($key, $selected)); } return $html; } /** * Rendert eine Checkbox * * @param string $name * @param string $label * @param string $selected * @param string $value * @param string $html_id * @return string */ function form_checkbox($name, $label, $selected, $value = 'checked', $html_id = null) { if (is_null($html_id)) { $html_id = $name; } return '
' . '
'; } /** * Rendert einen Radio * * @param string $name * @param string $label * @param string $selected * @param string $value * @return string */ function form_radio($name, $label, $selected, $value) { return '
' . '' . '
'; } /** * Rendert einen Infotext in das Formular * * @param string $label * @param string $text * @return string */ function form_info($label, $text = '') { if ($label == '') { return '' . icon('info-circle') . $text . ''; } if ($text == '') { return '

' . $label . '

'; } return form_element($label, '

' . $text . '

'); } /** * Rendert den Absenden-Button eines Formulars * * @param string $name * @param string $label * @param string $class * @param bool $wrapForm * @param string $buttonType * @return string */ function form_submit($name, $label, $class = '', $wrapForm = true, $buttonType = 'primary') { $button = ''; if (!$wrapForm) { return $button; } return form_element( null, $button ); } /** * Rendert ein Formular-Textfeld * * @param string $name * @param string $label * @param string $value * @param bool $disabled * @param int|null $maxlength * @param string|null $autocomplete * @param string|null $class * * @return string */ function form_text($name, $label, $value, $disabled = false, $maxlength = null, $autocomplete = null, $class = '') { $disabled = $disabled ? ' disabled="disabled"' : ''; $maxlength = $maxlength ? ' maxlength=' . (int)$maxlength : ''; $autocomplete = $autocomplete ? ' autocomplete="' . $autocomplete . '"' : ''; return form_element( $label, '', 'form_' . $name, $class ); } /** * Renders a text input with placeholder instead of label. * * @param String $name Input name * @param String $placeholder Placeholder * @param String $value The value * @param Boolean $disabled Is the field enabled? * @return string */ function form_text_placeholder($name, $placeholder, $value, $disabled = false) { $disabled = $disabled ? ' disabled="disabled"' : ''; return form_element( '', '' ); } /** * Rendert ein Formular-Emailfeld * * @param string $name * @param string $label * @param string $value * @param bool $disabled * @param string|null $autocomplete * @param int|null $maxlength * * @return string */ function form_email($name, $label, $value, $disabled = false, $autocomplete = null, $maxlength = null) { $disabled = $disabled ? ' disabled="disabled"' : ''; $autocomplete = $autocomplete ? ' autocomplete="' . $autocomplete . '"' : ''; $maxlength = $maxlength ? ' maxlength=' . (int)$maxlength : ''; return form_element( $label, '', 'form_' . $name ); } /** * Rendert ein Formular-Dateifeld * * @param string $name * @param string $label * @return string */ function form_file($name, $label) { return form_element( $label, sprintf('', $name), 'form_' . $name ); } /** * Rendert ein Formular-Passwortfeld * * @param string $name * @param string $label * @param bool $disabled * @return string */ function form_password($name, $label, $disabled = false) { $disabled = $disabled ? ' disabled="disabled"' : ''; return form_element( $label, sprintf( '', $name, config('min_password_length'), $disabled ), 'form_' . $name ); } /** * Renders a password input with placeholder instead of label. * * @param string $name * @param string $placeholder * @param bool $disabled * @return string */ function form_password_placeholder($name, $placeholder, $disabled = false) { $disabled = $disabled ? ' disabled="disabled"' : ''; return form_element( '', '', 'form_' . $name ); } /** * Rendert ein Formular-Textfeld * * @param string $name * @param string $label * @param string $value * @param bool $disabled * @return string */ function form_textarea($name, $label, $value, $disabled = false) { $disabled = $disabled ? ' disabled="disabled"' : ''; return form_element( $label, '', 'form_' . $name ); } /** * Rendert ein Formular-Auswahlfeld * * @param string $name * @param string $label * @param string[] $values * @param string $selected * @param string $selectText * @param string $class * @return string */ function form_select($name, $label, $values, $selected, $selectText = '', $class = '') { return form_element( $label, html_select_key('form_' . $name, $name, $values, $selected, $selectText), 'form_' . $name, $class ); } /** * Rendert ein Formular-Element * * @param string $label * @param string $input * @param string $for * @param string $class * @return string */ function form_element($label, $input, $for = '', $class = '') { $class = $class ? ' ' . $class : ''; if (empty($label)) { return '
' . $input . '
'; } return '
' . '' . $input . '
'; } /** * Rendert ein Formular * * @param string[] $elements * @param string $action * @param bool $inline * @return string */ function form($elements, $action = '', $inline = false, $btnGroup = false) { return '
' . join($elements) . form_csrf() . '
'; } /** * @return string */ function form_csrf() { return form_hidden('_token', session()->get('_token')); } /** * @param string $name * @param String[] $options * @param string $selected * @return string */ function html_options($name, $options, $selected = '') { $html = ''; foreach ($options as $value => $label) { $html .= '
' . '' . '' . '
'; } return $html; } /** * @param string $dom_id * @param string $name * @param string[] $rows * @param string $selected * @param string $selectText * @return string */ function html_select_key($dom_id, $name, $rows, $selected, $selectText = '') { $html = ''; return $html; }