The Framework PHP Helpers



Examples of PHP Helper class: "HelperInputText"

DOWNLOAD version 0.1.0
released at 2018-02-25 19:50 GMT

  1. Download Helpers (zip file)
  2. Unzip it in your vendors folder (e.g)
  3. Include autoload.php in your bootstrap file
    <?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();
  4. Result: Example of HelperInputText



Resume

It helps to create html element "input type text":
<input type="text" value="some text">

Examples:


Example 1


Live Html

Phone
@

PHP Code:

<?php
use TheFramework\Helpers\HelperLabel;
use TheFramework\Helpers\HelperInputText;
use TheFramework\Helpers\HelperDiv;
use TheFramework\Helpers\HelperButtonBasic;
use TheFramework\Helpers\HelperForm;

if(isset($_POST["emlEmail"]))//required
    //pr(): is an echo function
    pr("{email:{$_POST["emlEmail"]},phone:{$_POST["txtPhone"]}}","\$_POST");

//FIELD 1   PHONE
$oLabel = new HelperLabel();
$oLabel->set_for("txtPhone");
$oLabel->add_class("sr-only");//hides label
$oLabel->set_innerhtml("Phone");

$oPhone = new HelperInputText();
//$oPhone->set_type("tel"); //you can change to phone format.
//more examples: https://v4-alpha.getbootstrap.com/components/forms/#textual-inputs
$oPhone->set_id("txtPhone");
$oPhone->set_name("txtPhone");
$oPhone->add_class("form-control");
$oPhone->set_maxlength(100);
$oPhone->add_extras("placeholder","(0034) 654 333 222");
$oPhone->set_value((isset($_POST["txtPhone"])?$_POST["txtPhone"]:NULL));

$oDiv = new HelperDiv();
$oDiv->set_comments("divrow");
$oDiv->add_class("input-group mb-2 mr-sm-2 mb-sm-0");
$oDiv->add_inner_object(new HelperDiv("Phone",NULL,"input-group-addon"));
$oDiv->add_inner_object($oPhone);

//FIELD 2   EMAIL
$oLabel2 = clone $oLabel;
$oLabel2->set_for("emlEmail");
$oLabel2->set_class("sr-only");//hides label
$oLabel2->set_innerhtml("Username");

$oEmail = new HelperInputText();
$oEmail->set_type("email");//changed type
//more examples:https://v4-alpha.getbootstrap.com/components/forms/#textual-inputs
$oEmail->set_id("emlEmail");
$oEmail->set_name("emlEmail");
$oEmail->add_style("border: black 1px dashed");
$oEmail->add_class("form-control");
$oEmail->required();
$oEmail->set_value((isset($_POST["emlEmail"])?$_POST["emlEmail"]:NULL));
$oEmail->add_extras("placeholder","username@somedomain.io");
if(isset($_POST["emlEmail"]))
    $oEmail->add_extras("autofocus","autofocus");

$oDiv2 = new HelperDiv();
$oDiv2->add_class("input-group mb-2 mr-sm-2 mb-sm-0");
$oDiv2->add_inner_object(new HelperDiv("@",NULL,"input-group-addon","background:black;color:white"));
$oDiv2->add_inner_object($oEmail);

$oButton = new HelperButtonBasic();
$oButton->set_type("submit");
$oButton->add_class("btn btn-primary");
$oButton->set_innerhtml("Submit");

$oForm = new HelperForm();
$oForm->set_id("myForm");
$oForm->set_comments("This is a form");
$oForm->set_method("post");
$oForm->add_style("border:1px dashed #4f9fcf;");
$oForm->add_style("padding:5px;");
$oForm->add_class("form-inline");
$oForm->add_inner_object($oLabel);
$oForm->add_inner_object($oDiv);
$oForm->add_inner_object($oLabel2);
$oForm->add_inner_object($oDiv2);
$oForm->add_inner_object($oButton);
$oForm->show(); //show() is the same as echo $oForm->get_html();
?>

HTML Result:

<!-- This is a form -->
<form id="myForm" method="post" class="form-inline" style="border:1px dashed #4f9fcf;;padding:5px;">
<label for="txtPhone" class="sr-only">Phone</label>
<div class="input-group mb-2 mr-sm-2 mb-sm-0">
<div class="input-group-addon">
Phone</div>
<input type="text" id="txtPhone" name="txtPhone" maxlength="100" class="form-control" placeholder="(0034) 654 333 222">
</div>
<label for="emlEmail" class="sr-only">Username</label>
<div class="input-group mb-2 mr-sm-2 mb-sm-0">
<div class="input-group-addon" style="background:black;color:white">@</div>
<input type="email" id="emlEmail" name="emlEmail" maxlength="50" required="" class="form-control" style="border: black 1px dashed" placeholder="username@somedomain.io">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>

Example 2

Live Html


PHP Code:

<?php
use TheFramework\Helpers\HelperLabel;
use TheFramework\Helpers\HelperInputText;
//input text types
//https://v4-alpha.getbootstrap.com/components/forms/#textual-inputs
$arTypes = ["text","search","email","url","tel","password","number"
    ,"datetime-local","date","month","week","time"
    ,"color"];

foreach($arTypes as $sType)
{
    $oLabel = new HelperLabel("txt-$sType");
    $oLabel->set_innerhtml("<b>$sType: </b>");
    echo $oLabel->get_html();
    
    $oInput = new HelperInputText("txt-$sType");
    $oInput->set_type($sType);
    $oInput->add_class("form-control");
    $oInput->show();
    //echo "<hr/>";
}
?>

HTML Result:

<label for="txt-text"><b>text: </b></label>
<input type="text" id="txt-text" maxlength="50" class="form-control">
<label for="txt-search"><b>search: </b></label>
<input type="search" id="txt-search" maxlength="50" class="form-control">
<label for="txt-email"><b>email: </b></label>
<input type="email" id="txt-email" maxlength="50" class="form-control">
<label for="txt-url"><b>url: </b></label>
<input type="url" id="txt-url" maxlength="50" class="form-control">
<label for="txt-tel"><b>tel: </b></label>
<input type="tel" id="txt-tel" maxlength="50" class="form-control">
<label for="txt-password"><b>password: </b></label>
<input type="password" id="txt-password" maxlength="50" class="form-control">
<label for="txt-number"><b>number: </b></label>
<input type="number" id="txt-number" maxlength="50" class="form-control">
<label for="txt-datetime-local"><b>datetime-local: </b></label>
<input type="datetime-local" id="txt-datetime-local" maxlength="50" class="form-control">
<label for="txt-date"><b>date: </b></label>
<input type="date" id="txt-date" maxlength="50" class="form-control">
<label for="txt-month"><b>month: </b></label>
<input type="month" id="txt-month" maxlength="50" class="form-control">
<label for="txt-week"><b>week: </b></label>
<input type="week" id="txt-week" maxlength="50" class="form-control">
<label for="txt-time"><b>time: </b></label>
<input type="time" id="txt-time" maxlength="50" class="form-control">
<label for="txt-color"><b>color: </b></label>
<input type="color" id="txt-color" maxlength="50" class="form-control">