Add checkbox to form builder
This commit is contained in:
parent
6ceeeaa087
commit
69c634ea99
@ -173,33 +173,50 @@ HTMLTOP;
|
|||||||
$required = $item["required"] ? "required" : "";
|
$required = $item["required"] ? "required" : "";
|
||||||
$id = empty($item["id"]) ? "" : "id=\"$item[id]\"";
|
$id = empty($item["id"]) ? "" : "id=\"$item[id]\"";
|
||||||
$pattern = empty($item["pattern"]) ? "" : "pattern=\"$item[pattern]\"";
|
$pattern = empty($item["pattern"]) ? "" : "pattern=\"$item[pattern]\"";
|
||||||
|
if (empty($item['type'])) {
|
||||||
|
$item['type'] = "text";
|
||||||
|
}
|
||||||
$itemhtml = "";
|
$itemhtml = "";
|
||||||
|
$itemlabel = "";
|
||||||
|
if ($item['type'] != "checkbox") {
|
||||||
|
$itemlabel = "<label class=\"mb-0\">$item[label]:</label>";
|
||||||
|
}
|
||||||
$itemhtml .= <<<ITEMTOP
|
$itemhtml .= <<<ITEMTOP
|
||||||
\n\n <div class="col-12 col-md-$item[width]">
|
\n\n <div class="col-12 col-md-$item[width]">
|
||||||
<div class="form-group mb-3">
|
<div class="form-group mb-3">
|
||||||
<label class="mb-0">$item[label]:</label>
|
$itemlabel
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<div class="input-group-prepend">
|
<div class="input-group-prepend">
|
||||||
<span class="input-group-text"><i class="$item[icon]"></i></span>
|
<span class="input-group-text"><i class="$item[icon]"></i></span>
|
||||||
</div>
|
</div>
|
||||||
ITEMTOP;
|
ITEMTOP;
|
||||||
if (empty($item['type']) || $item['type'] != "select") {
|
switch ($item['type']) {
|
||||||
$itemhtml .= <<<INPUT
|
case "select":
|
||||||
\n <input type="$item[type]" name="$item[name]" $id class="form-control" aria-label="$item[label]" minlength="$item[minlength]" maxlength="$item[maxlength]" $pattern value="$item[value]" $required />
|
$itemhtml .= <<<SELECT
|
||||||
INPUT;
|
|
||||||
} else {
|
|
||||||
$itemhtml .= <<<SELECT
|
|
||||||
\n <select class="form-control" name="$item[name]" aria-label="$item[label]" $required>
|
\n <select class="form-control" name="$item[name]" aria-label="$item[label]" $required>
|
||||||
SELECT;
|
SELECT;
|
||||||
foreach ($item['options'] as $value => $label) {
|
foreach ($item['options'] as $value => $label) {
|
||||||
$selected = "";
|
$selected = "";
|
||||||
if (!empty($item['value']) && $value == $item['value']) {
|
if (!empty($item['value']) && $value == $item['value']) {
|
||||||
$selected = " selected";
|
$selected = " selected";
|
||||||
|
}
|
||||||
|
$itemhtml .= "\n <option value=\"$value\"$selected>$label</option>";
|
||||||
}
|
}
|
||||||
$itemhtml .= "\n <option value=\"$value\"$selected>$label</option>";
|
$itemhtml .= "\n </select>";
|
||||||
}
|
break;
|
||||||
$itemhtml .= "\n </select>";
|
case "checkbox":
|
||||||
|
$itemhtml .= <<<CHECKBOX
|
||||||
|
\n <div class="form-group form-check">
|
||||||
|
<input type="checkbox" name="$item[name]" $id class="form-check-input" value="$item[value]" $required aria-label="$item[label]">
|
||||||
|
<label class="form-check-label">$item[label]</label>
|
||||||
|
</div>
|
||||||
|
CHECKBOX;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$itemhtml .= <<<INPUT
|
||||||
|
\n <input type="$item[type]" name="$item[name]" $id class="form-control" aria-label="$item[label]" minlength="$item[minlength]" maxlength="$item[maxlength]" $pattern value="$item[value]" $required />
|
||||||
|
INPUT;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($item["error"])) {
|
if (!empty($item["error"])) {
|
||||||
|
@ -18,6 +18,7 @@ $form->addHiddenInput("page", "form");
|
|||||||
|
|
||||||
$form->addInput("name", "John", "text", true, null, null, "Your name", "fas fa-user", 6, 5, 20, "John(ny)?|Steve", "Invalid name, please enter John, Johnny, or Steve.");
|
$form->addInput("name", "John", "text", true, null, null, "Your name", "fas fa-user", 6, 5, 20, "John(ny)?|Steve", "Invalid name, please enter John, Johnny, or Steve.");
|
||||||
$form->addInput("location", "", "select", true, null, ["1" => "Here", "2" => "There"], "Location", "fas fa-map-marker");
|
$form->addInput("location", "", "select", true, null, ["1" => "Here", "2" => "There"], "Location", "fas fa-map-marker");
|
||||||
|
$form->addInput("box", "1", "checkbox", true, null, null, "I agree to the terms of service");
|
||||||
|
|
||||||
$form->addButton("Submit", "fas fa-save", null, "submit", "savebtn");
|
$form->addButton("Submit", "fas fa-save", null, "submit", "savebtn");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user