'; } /** * Rendert ein Zahlenfeld mit Buttons zum verstellen * * @param string $name * @param string $label * @param int $value * @param array $data_attributes * @param bool $isDisabled * @return string */ function form_spinner(string $name, string $label, int $value, array $data_attributes = [], bool $isDisabled = false) { $id = 'spinner-' . $name; $attr = ''; foreach ($data_attributes as $attr_key => $attr_value) { $attr .= ' data-' . $attr_key . '="' . $attr_value . '"'; } $disabled = $isDisabled ? ' disabled' : ''; return form_element($label, '
', $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 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 '
' . '
'; } /** * Renders a radio button * * @param string $name * @param string $label * @param string $selected * @param string $value * @return string */ function form_radio($name, $label, $selected, $value) { $value = htmlspecialchars((string) $value); $id = preg_replace('/\s/', '-', $name . '_' . $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 * @param string $title * @param array $dataAttributes * @return string */ function form_submit( $name, $label, $class = '', $wrapForm = true, $buttonType = 'primary', $title = '', array $dataAttributes = [] ) { $add = ''; foreach ($dataAttributes as $dataType => $dataValue) { $add .= ' data-' . $dataType . '="' . htmlspecialchars($dataValue) . '"'; } $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 * @param array $data_attributes * @return string */ function form_text($name, $label, $value, $disabled = false, $maxlength = null, $autocomplete = null, $class = '', $data_attributes = []) { $disabled = $disabled ? ' disabled="disabled"' : ''; $maxlength = $maxlength ? ' maxlength=' . (int) $maxlength : ''; $autocomplete = $autocomplete ? ' autocomplete="' . $autocomplete . '"' : ''; $attr = ''; foreach ($data_attributes as $attr_key => $attr_value) { $attr .= ' data-' . $attr_key . '="' . $attr_value . '"'; } return form_element( $label, '', 'form_' . $name, $class ); } /** * Rendert ein Formular-Passwortfeld * * @param string $name * @param string $label * @param string $autocomplete * @param bool $disabled * @return string */ function form_password($name, $label, $autocomplete, $disabled = false) { $disabled = $disabled ? ' disabled="disabled"' : ''; return form_element( $label, sprintf( '', $name, config('min_password_length'), $autocomplete, $disabled ), '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 string $style * @return string */ function form($elements, $action = '', $style = '', $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; }