Add textarea to FormBuilder

master
Skylar Ittner 5 years ago
parent e66280e07a
commit 7173a50c36

@ -178,7 +178,10 @@ HTMLTOP;
} }
$itemhtml = ""; $itemhtml = "";
$itemlabel = ""; $itemlabel = "";
if ($item['type'] != "checkbox") {
if ($item['type'] == "textarea") {
$itemlabel = "<label class=\"mb-0\"><i class=\"$item[icon]\"></i> $item[label]:</label>";
} else if ($item['type'] != "checkbox") {
$itemlabel = "<label class=\"mb-0\">$item[label]:</label>"; $itemlabel = "<label class=\"mb-0\">$item[label]:</label>";
} }
$strippedlabel = strip_tags($item['label']); $strippedlabel = strip_tags($item['label']);
@ -186,13 +189,16 @@ HTMLTOP;
\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">
$itemlabel $itemlabel
<div class="input-group"> ITEMTOP;
$inputgrouptop = <<<INPUTG
\n <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; INPUTG;
switch ($item['type']) { switch ($item['type']) {
case "select": case "select":
$itemhtml .= $inputgrouptop;
$itemhtml .= <<<SELECT $itemhtml .= <<<SELECT
\n <select class="form-control" name="$item[name]" aria-label="$strippedlabel" $required> \n <select class="form-control" name="$item[name]" aria-label="$strippedlabel" $required>
SELECT; SELECT;
@ -206,6 +212,7 @@ SELECT;
$itemhtml .= "\n </select>"; $itemhtml .= "\n </select>";
break; break;
case "checkbox": case "checkbox":
$itemhtml .= $inputgrouptop;
$itemhtml .= <<<CHECKBOX $itemhtml .= <<<CHECKBOX
\n <div class="form-group form-check"> \n <div class="form-group form-check">
<input type="checkbox" name="$item[name]" $id class="form-check-input" value="$item[value]" $required aria-label="$strippedlabel"> <input type="checkbox" name="$item[name]" $id class="form-check-input" value="$item[value]" $required aria-label="$strippedlabel">
@ -213,7 +220,14 @@ SELECT;
</div> </div>
CHECKBOX; CHECKBOX;
break; break;
case "textarea":
$val = htmlentities($item['value']);
$itemhtml .= <<<TEXTAREA
\n <textarea class="form-control" id="info" name="$item[name]" aria-label="$strippedlabel" minlength="$item[minlength]" maxlength="$item[maxlength]" $required>$val</textarea>
TEXTAREA;
break;
default: default:
$itemhtml .= $inputgrouptop;
$itemhtml .= <<<INPUT $itemhtml .= <<<INPUT
\n <input type="$item[type]" name="$item[name]" $id class="form-control" aria-label="$strippedlabel" minlength="$item[minlength]" maxlength="$item[maxlength]" $pattern value="$item[value]" $required /> \n <input type="$item[type]" name="$item[name]" $id class="form-control" aria-label="$strippedlabel" minlength="$item[minlength]" maxlength="$item[maxlength]" $pattern value="$item[value]" $required />
INPUT; INPUT;
@ -227,9 +241,11 @@ INPUT;
</div> </div>
ERROR; ERROR;
} }
if ($item["type"] != "textarea") {
$itemhtml .= "\n </div>";
}
$itemhtml .= <<<ITEMBOTTOM $itemhtml .= <<<ITEMBOTTOM
\n </div> \n </div>
</div>
</div>\n </div>\n
ITEMBOTTOM; ITEMBOTTOM;
$html .= $itemhtml; $html .= $itemhtml;

@ -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("textbox", "Hello world", "textarea", true, null, null, "Text area", "fas fa-font");
$form->addInput("box", "1", "checkbox", true, null, null, "I agree to the terms of service"); $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…
Cancel
Save