<?php /* lets suposse you have this folder tree yourproject/ vendors/ lib_1/ lib_n/ theframework/ -->uncompressed zip helpers/ index.php */ //this file is: yourproject/index.php include_once("vendors/theframework/helpers/autoload.php"); use TheFramework\Helpers\HelperInputText; $oInput = new HelperInputText(); $oInput->set_value("Hello World"); $oInput->add_class("form-control"); $oInput->show();
It helps to create html element "input type checkbox":
<input type="checkbox">
use TheFramework\Helpers\HelperForm; use TheFramework\Helpers\HelperCheckbox; use TheFramework\Helpers\HelperRaw; $arChoose = ["val_a"=>"Text a","val_b"=>"Text b","val_c"=>"Text c","val_d"=>"Text d","val_e"=>"Text e"]; $arChecks = []; $i = 0; foreach($arChoose as $sK=>$sLabel) { $arChecks[] = new HelperRaw("<div class=\"form-check\"><label class=\"form-check-label\">"); $arChecks[$sK] = new HelperCheckbox([$sK=>$sLabel]); $arChecks[$sK]->set_id("chkId_$i"); $arChecks[$sK]->set_name("chkChooseName"); $arChecks[$sK]->set_values_to_check("val_a|val_d");//or ["val_a","val_d"] $arChecks[$sK]->add_class("form-check-input"); $arChecks[] = new HelperRaw("</label></div>"); $i++; } $oForm = new HelperForm(); $oForm->set_comments("This is a comment"); $oForm->add_style("border:1px dashed #4f9fcf"); $oForm->add_style("padding:5px"); $oForm->set_id("myForm"); $oForm->add_controls($arChecks); $oForm->show(); ?>
<!-- This is a comment --> <form id="myForm" method="post" style="border:1px dashed #4f9fcf;padding:5px;"> <div class="form-check"><label class="form-check-label"><input type="checkbox" id="chkId_0" name="chkChooseName[]" value="val_a" class="form-check-input" checked="">Text a</label></div><div class="form-check"><label class="form-check-label"><input type="checkbox" id="chkId_1" name="chkChooseName[]" value="val_b" class="form-check-input">Text b</label></div><div class="form-check"><label class="form-check-label"><input type="checkbox" id="chkId_2" name="chkChooseName[]" value="val_c" class="form-check-input">Text c</label></div><div class="form-check"><label class="form-check-label"><input type="checkbox" id="chkId_3" name="chkChooseName[]" value="val_d" class="form-check-input" checked="">Text d</label></div><div class="form-check"><label class="form-check-label"><input type="checkbox" id="chkId_4" name="chkChooseName[]" value="val_e" class="form-check-input">Text e</label></div> </form>
<?php $arChecks = []; foreach($arChoose as $sK=>$sLabel) { $arChecks[] = new HelperRaw("<div class=\"form-check form-check-inline\"><label class=\"form-check-label\">"); $arChecks[$sK] = new HelperCheckbox([$sK=>$sLabel]); $arChecks[$sK]->set_id("chkId_$i"); $arChecks[$sK]->set_name("chkChooseName"); $arChecks[$sK]->set_values_to_check("val_a|val_d");//or ["val_a","val_d"] $arChecks[$sK]->add_class("form-check-input"); $arChecks[] = new HelperRaw("</label></div>"); $i++; } $oForm = new HelperForm(); $oForm->add_style("border:1px dashed #4f9fcf"); $oForm->add_style("padding:5px"); $oForm->set_id("myForm1"); $oForm->add_controls($arChecks); $oForm->show(); ?>
<form id="myForm1" method="post" style="border:1px dashed #4f9fcf;padding:5px;"> <div class="form-check form-check-inline"><label class="form-check-label"><input type="checkbox" id="chkId_5" name="chkChooseName[]" value="val_a" class="form-check-input" checked="">Text a</label></div><div class="form-check form-check-inline"><label class="form-check-label"><input type="checkbox" id="chkId_6" name="chkChooseName[]" value="val_b" class="form-check-input">Text b</label></div><div class="form-check form-check-inline"><label class="form-check-label"><input type="checkbox" id="chkId_7" name="chkChooseName[]" value="val_c" class="form-check-input">Text c</label></div><div class="form-check form-check-inline"><label class="form-check-label"><input type="checkbox" id="chkId_8" name="chkChooseName[]" value="val_d" class="form-check-input" checked="">Text d</label></div><div class="form-check form-check-inline"><label class="form-check-label"><input type="checkbox" id="chkId_9" name="chkChooseName[]" value="val_e" class="form-check-input">Text e</label></div> </form>
<?php use TheFramework\Helpers\HelperFieldset; use TheFramework\Helpers\HelperLegend; $oForm = new HelperForm(); $oForm->set_comments("This is a comment"); $oForm->add_style("border:1px dashed #4f9fcf"); $oForm->add_style("padding:5px"); $oForm->set_id("myForm"); $arChoose = ["val_a"=>"Text a","val_b"=>"Text b","val_c"=>"Text c","val_d"=>"Text d","val_e"=>"Text e"]; $oCheckbox = new HelperCheckbox($arChoose); $oCheckbox->set_id("chkChooseId"); $oCheckbox->set_name("chkChooseName"); $oCheckbox->add_class("form-check-input"); $oCheckbox->set_style("margin:3px;"); $arValschecked = ["val_b","val_c"]; $oCheckbox->set_values_to_check($arValschecked); //$oCheckbox->show(); $oFieldset = new HelperFieldset(); $oFieldset->add_class("form-group"); $oCheckbox->set_fieldset($oFieldset); $oCheckbox->set_legend(new HelperLegend("Legend for checkboxes")); $oForm->add_control($oCheckbox); $oForm->show(); ?>
<form id="myForm" method="post" style="border:1px dashed #4f9fcf;padding:5px;"> <fieldset class="form-group"><legend>Legend for checkboxes</legend> <input type="checkbox" id="chkChooseId_0" name="chkChooseName[]" value="val_a" class="form-check-input" style="margin:3px;">Text a<input type="checkbox" id="chkChooseId_1" name="chkChooseName[]" value="val_b" class="form-check-input" style="margin:3px;" checked="">Text b<input type="checkbox" id="chkChooseId_2" name="chkChooseName[]" value="val_c" class="form-check-input" style="margin:3px;" checked="">Text c<input type="checkbox" id="chkChooseId_3" name="chkChooseName[]" value="val_d" class="form-check-input" style="margin:3px;">Text d<input type="checkbox" id="chkChooseId_4" name="chkChooseName[]" value="val_e" class="form-check-input" style="margin:3px;">Text e</fieldset> </form>