summaryrefslogtreecommitdiff
path: root/includes/sys_form.php
diff options
context:
space:
mode:
authorBot <bot@myigel.name>2017-01-02 03:57:23 +0100
committerIgor Scheller <igor.scheller@igorshp.de>2017-01-02 03:57:23 +0100
commit7313e15ce8236e19331fb6639a3a5b97c8f06ecd (patch)
tree399e5eaa403d6dd5993ca8fb6f2162319d2ed2e1 /includes/sys_form.php
parentb839e401062b294292fdcbd7e30b79bc149fab6f (diff)
PSR-2 formatting
Diffstat (limited to 'includes/sys_form.php')
-rw-r--r--includes/sys_form.php211
1 files changed, 115 insertions, 96 deletions
diff --git a/includes/sys_form.php b/includes/sys_form.php
index 98ef2134..4a97b672 100644
--- a/includes/sys_form.php
+++ b/includes/sys_form.php
@@ -10,15 +10,17 @@
* The value
* @return string rendered html
*/
-function form_hidden($name, $value) {
- return '<input type="hidden" name="' . $name . '" value="' . $value . '" />';
+function form_hidden($name, $value)
+{
+ return '<input type="hidden" name="' . $name . '" value="' . $value . '" />';
}
/**
* Rendert ein Zahlenfeld mit Buttons zum verstellen
*/
-function form_spinner($name, $label, $value) {
- return form_element($label, '
+function form_spinner($name, $label, $value)
+{
+ return form_element($label, '
<div class="input-group">
<input id="spinner-' . $name . '" class="form-control" type="text" name="' . $name . '" value="' . $value . '" />
<div class="input-group-btn">
@@ -54,12 +56,13 @@ function form_spinner($name, $label, $value) {
* Earliest possible date
* @return HTML
*/
-function form_date($name, $label, $value, $start_date = '', $end_date = '') {
- $dom_id = $name . '-date';
- $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, '
+function form_date($name, $label, $value, $start_date = '', $end_date = '')
+{
+ $dom_id = $name . '-date';
+ $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, '
<div class="input-group date" id="' . $dom_id . '">
<input type="text" name="' . $name . '" class="form-control" value="' . $value . '"><span class="input-group-addon">' . glyph('th') . '</span>
</div>
@@ -89,12 +92,13 @@ function form_date($name, $label, $value, $start_date = '', $end_date = '') {
* @param
* selected Array mit den Keys, die ausgewählt sind
*/
-function form_checkboxes($name, $label, $items, $selected) {
- $html = form_element($label, '');
- foreach ($items as $key => $item) {
- $html .= form_checkbox($name . '_' . $key, $item, array_search($key, $selected) !== false);
- }
- return $html;
+function form_checkboxes($name, $label, $items, $selected)
+{
+ $html = form_element($label, '');
+ foreach ($items as $key => $item) {
+ $html .= form_checkbox($name . '_' . $key, $item, array_search($key, $selected) !== false);
+ }
+ return $html;
}
/**
@@ -111,68 +115,74 @@ function form_checkboxes($name, $label, $items, $selected) {
* @param
* disabled Wie selected, nur dass die entsprechenden Checkboxen deaktiviert statt markiert sind
*/
-function form_multi_checkboxes($names, $label, $items, $selected, $disabled = []) {
- $html = "<table><thead><tr>";
- foreach ($names as $title) {
- $html .= "<th>$title</th>";
- }
- $html .= "</tr></thead><tbody>";
- foreach ($items as $key => $item) {
- $html .= "<tr>";
- foreach ($names as $name => $title) {
- $dom_id = $name . '_' . $key;
- $sel = array_search($key, $selected[$name]) !== false ? ' checked="checked"' : "";
- if (! empty($disabled) && ! empty($disabled[$name]) && array_search($key, $disabled[$name]) !== false) {
- $sel .= ' disabled="disabled"';
- }
- $html .= '<td style="text-align: center;"><input type="checkbox" id="' . $dom_id . '" name="' . $name . '[]" value="' . $key . '"' . $sel . ' /></td>';
+function form_multi_checkboxes($names, $label, $items, $selected, $disabled = [])
+{
+ $html = "<table><thead><tr>";
+ foreach ($names as $title) {
+ $html .= "<th>$title</th>";
+ }
+ $html .= "</tr></thead><tbody>";
+ foreach ($items as $key => $item) {
+ $html .= "<tr>";
+ foreach ($names as $name => $title) {
+ $dom_id = $name . '_' . $key;
+ $sel = array_search($key, $selected[$name]) !== false ? ' checked="checked"' : "";
+ if (! empty($disabled) && ! empty($disabled[$name]) && array_search($key, $disabled[$name]) !== false) {
+ $sel .= ' disabled="disabled"';
+ }
+ $html .= '<td style="text-align: center;"><input type="checkbox" id="' . $dom_id . '" name="' . $name . '[]" value="' . $key . '"' . $sel . ' /></td>';
+ }
+ $html .= '<td><label for="' . $dom_id . '">' . $item . '</label></td></tr>';
}
- $html .= '<td><label for="' . $dom_id . '">' . $item . '</label></td></tr>';
- }
- $html .= "</tbody></table>";
- return form_element($label, $html);
+ $html .= "</tbody></table>";
+ return form_element($label, $html);
}
/**
* Rendert eine Checkbox
*/
-function form_checkbox($name, $label, $selected, $value = 'checked') {
- return '<div class="checkbox"><label><input type="checkbox" id="' . $name . '" name="' . $name . '" value="' . $value . '"' . ($selected ? ' checked="checked"' : '') . ' /> ' . $label . '</label></div>';
+function form_checkbox($name, $label, $selected, $value = 'checked')
+{
+ return '<div class="checkbox"><label><input type="checkbox" id="' . $name . '" name="' . $name . '" value="' . $value . '"' . ($selected ? ' checked="checked"' : '') . ' /> ' . $label . '</label></div>';
}
/**
* Rendert einen Radio
*/
-function form_radio($name, $label, $selected, $value) {
- return '<div class="radio"><label><input type="radio" id="' . $name . '" name="' . $name . '" value="' . $value . '"' . ($selected ? ' checked="checked"' : '') . ' /> ' . $label . '</label></div>';
+function form_radio($name, $label, $selected, $value)
+{
+ return '<div class="radio"><label><input type="radio" id="' . $name . '" name="' . $name . '" value="' . $value . '"' . ($selected ? ' checked="checked"' : '') . ' /> ' . $label . '</label></div>';
}
/**
* Rendert einen Infotext in das Formular
*/
-function form_info($label, $text = "") {
- if ($label == "") {
- return '<span class="help-block">' . glyph('info-sign') . $text . '</span>';
- }
- if ($text == "") {
- return '<h4>' . $label . '</h4>';
- }
- return form_element($label, '<p class="form-control-static">' . $text . '</p>', '');
+function form_info($label, $text = "")
+{
+ if ($label == "") {
+ return '<span class="help-block">' . glyph('info-sign') . $text . '</span>';
+ }
+ if ($text == "") {
+ return '<h4>' . $label . '</h4>';
+ }
+ return form_element($label, '<p class="form-control-static">' . $text . '</p>', '');
}
/**
* Rendert den Absenden-Button eines Formulars
*/
-function form_submit($name, $label) {
- return form_element('<input class="btn btn-primary" type="submit" name="' . $name . '" value="' . $label . '" />', "");
+function form_submit($name, $label)
+{
+ return form_element('<input class="btn btn-primary" type="submit" name="' . $name . '" value="' . $label . '" />', "");
}
/**
* Rendert ein Formular-Textfeld
*/
-function form_text($name, $label, $value, $disabled = false) {
- $disabled = $disabled ? ' disabled="disabled"' : '';
- return form_element($label, '<input class="form-control" id="form_' . $name . '" type="text" name="' . $name . '" value="' . htmlspecialchars($value) . '" ' . $disabled . '/>', 'form_' . $name);
+function form_text($name, $label, $value, $disabled = false)
+{
+ $disabled = $disabled ? ' disabled="disabled"' : '';
+ return form_element($label, '<input class="form-control" id="form_' . $name . '" type="text" name="' . $name . '" value="' . htmlspecialchars($value) . '" ' . $disabled . '/>', 'form_' . $name);
}
/**
@@ -187,95 +197,104 @@ function form_text($name, $label, $value, $disabled = false) {
* @param Boolean $disabled
* Is the field enabled?
*/
-function form_text_placeholder($name, $placeholder, $value, $disabled = false) {
- $disabled = $disabled ? ' disabled="disabled"' : '';
- return form_element('', '<input class="form-control" id="form_' . $name . '" type="text" name="' . $name . '" value="' . htmlspecialchars($value) . '" placeholder="' . $placeholder . '" ' . $disabled . '/>');
+function form_text_placeholder($name, $placeholder, $value, $disabled = false)
+{
+ $disabled = $disabled ? ' disabled="disabled"' : '';
+ return form_element('', '<input class="form-control" id="form_' . $name . '" type="text" name="' . $name . '" value="' . htmlspecialchars($value) . '" placeholder="' . $placeholder . '" ' . $disabled . '/>');
}
/**
* Rendert ein Formular-Emailfeld
*/
-function form_email($name, $label, $value, $disabled = false) {
- $disabled = $disabled ? ' disabled="disabled"' : '';
- return form_element($label, '<input class="form-control" id="form_' . $name . '" type="email" name="' . $name . '" value="' . htmlspecialchars($value) . '" ' . $disabled . '/>', 'form_' . $name);
+function form_email($name, $label, $value, $disabled = false)
+{
+ $disabled = $disabled ? ' disabled="disabled"' : '';
+ return form_element($label, '<input class="form-control" id="form_' . $name . '" type="email" name="' . $name . '" value="' . htmlspecialchars($value) . '" ' . $disabled . '/>', 'form_' . $name);
}
/**
* Rendert ein Formular-Dateifeld
*/
-function form_file($name, $label) {
- return form_element($label, '<input id="form_' . $name . '" type="file" name="' . $name . '" />', 'form_' . $name);
+function form_file($name, $label)
+{
+ return form_element($label, '<input id="form_' . $name . '" type="file" name="' . $name . '" />', 'form_' . $name);
}
/**
* Rendert ein Formular-Passwortfeld
*/
-function form_password($name, $label, $disabled = false) {
- $disabled = $disabled ? ' disabled="disabled"' : '';
- return form_element($label, '<input class="form-control" id="form_' . $name . '" type="password" name="' . $name . '" value="" ' . $disabled . '/>', 'form_' . $name);
+function form_password($name, $label, $disabled = false)
+{
+ $disabled = $disabled ? ' disabled="disabled"' : '';
+ return form_element($label, '<input class="form-control" id="form_' . $name . '" type="password" name="' . $name . '" value="" ' . $disabled . '/>', 'form_' . $name);
}
/**
* Renders a password input with placeholder instead of label.
*/
-function form_password_placeholder($name, $placeholder, $disabled = false) {
- $disabled = $disabled ? ' disabled="disabled"' : '';
- return form_element('', '<input class="form-control" id="form_' . $name . '" type="password" name="' . $name . '" value="" placeholder="' . $placeholder . '" ' . $disabled . '/>', 'form_' . $name);
+function form_password_placeholder($name, $placeholder, $disabled = false)
+{
+ $disabled = $disabled ? ' disabled="disabled"' : '';
+ return form_element('', '<input class="form-control" id="form_' . $name . '" type="password" name="' . $name . '" value="" placeholder="' . $placeholder . '" ' . $disabled . '/>', 'form_' . $name);
}
/**
* Rendert ein Formular-Textfeld
*/
-function form_textarea($name, $label, $value, $disabled = false) {
- $disabled = $disabled ? ' disabled="disabled"' : '';
- return form_element($label, '<textarea rows="5" class="form-control" id="form_' . $name . '" type="text" name="' . $name . '" ' . $disabled . '>' . $value . '</textarea>', 'form_' . $name);
+function form_textarea($name, $label, $value, $disabled = false)
+{
+ $disabled = $disabled ? ' disabled="disabled"' : '';
+ return form_element($label, '<textarea rows="5" class="form-control" id="form_' . $name . '" type="text" name="' . $name . '" ' . $disabled . '>' . $value . '</textarea>', 'form_' . $name);
}
/**
* Rendert ein Formular-Auswahlfeld
*/
-function form_select($name, $label, $values, $selected) {
- return form_element($label, html_select_key('form_' . $name, $name, $values, $selected), 'form_' . $name);
+function form_select($name, $label, $values, $selected)
+{
+ return form_element($label, html_select_key('form_' . $name, $name, $values, $selected), 'form_' . $name);
}
/**
* Rendert ein Formular-Element
*/
-function form_element($label, $input, $for = "") {
- if ($label == '') {
- return '<div class="form-group">' . $input . '</div>';
- }
+function form_element($label, $input, $for = "")
+{
+ if ($label == '') {
+ return '<div class="form-group">' . $input . '</div>';
+ }
- return '<div class="form-group">' . '<label for="' . $for . '">' . $label . '</label>' . $input . '</div>';
+ return '<div class="form-group">' . '<label for="' . $for . '">' . $label . '</label>' . $input . '</div>';
}
/**
* Rendert ein Formular
*/
-function form($elements, $action = "") {
- return '<form role="form" action="' . $action . '" enctype="multipart/form-data" method="post">' . join($elements) . '</form>';
+function form($elements, $action = "")
+{
+ return '<form role="form" action="' . $action . '" enctype="multipart/form-data" method="post">' . join($elements) . '</form>';
}
-function html_options($name, $options, $selected = "") {
- $html = "";
- foreach ($options as $value => $label) {
- $html .= '<input type="radio"' . ($value == $selected ? ' checked="checked"' : '') . ' name="' . $name . '" value="' . $value . '"> ' . $label;
- }
+function html_options($name, $options, $selected = "")
+{
+ $html = "";
+ foreach ($options as $value => $label) {
+ $html .= '<input type="radio"' . ($value == $selected ? ' checked="checked"' : '') . ' name="' . $name . '" value="' . $value . '"> ' . $label;
+ }
- return $html;
+ return $html;
}
-function html_select_key($dom_id, $name, $rows, $selected) {
- $html = '<select class="form-control" id="' . $dom_id . '" name="' . $name . '">';
- foreach ($rows as $key => $row) {
- if (($key == $selected) || ($row == $selected)) {
- $html .= '<option value="' . $key . '" selected="selected">' . $row . '</option>';
- } else {
- $html .= '<option value="' . $key . '">' . $row . '</option>';
+function html_select_key($dom_id, $name, $rows, $selected)
+{
+ $html = '<select class="form-control" id="' . $dom_id . '" name="' . $name . '">';
+ foreach ($rows as $key => $row) {
+ if (($key == $selected) || ($row == $selected)) {
+ $html .= '<option value="' . $key . '" selected="selected">' . $row . '</option>';
+ } else {
+ $html .= '<option value="' . $key . '">' . $row . '</option>';
+ }
}
- }
- $html .= '</select>';
- return $html;
+ $html .= '</select>';
+ return $html;
}
-
-?> \ No newline at end of file