Generating standard form controls with saving the state of the elements after the form is submitted.
Static class Nemiro\UI\Html
can generate some controls HTML.
Almost every method in addition to the standard parameters, accepts parameter $htmlAttributes
, which can be enumerated a list of additional html-attributes. For example:
<?=Nemiro\UI\Html::TextBox('username', NULL, array('maxlength' => '20', 'class' => 'form-control', 'placeholder' => 'Input your name'))?>
<input type="text" name="username" id="username" maxlength="20" class="form-control" placeholder="Input your name">
When submitting a form, all of these values are automatically restored. There is no need to restore the values manually.
Fill out the form and send. After reloading the page, the form values are automatically restored (only for PHP version).
When placing the label, required parameter is the label text.
<?=Nemiro\UI\Html::Label('Simple label')?>
<label>Simple label</label>
If you want to bind a label to specified control, it is necessary to set the identifier for the second parameter.
<input type="checkbox" name="parentId" id="parentId" />
<?=Nemiro\UI\Html::Label('click me', 'parentId')?>
<input type="checkbox" name="parentId" id="parentId" />
<label for="parentId">click me</label>
To place a CheckBox must specify name of the element. By the name you can get the value of the element to the server, after submitting the form.
<?=Nemiro\UI\Html::CheckBox('checkbox1')?>
<input type="checkbox" name="checkbox1" id="checkbox1" value="true" />
The value
parameter has a default value is true
, but you can override it.
<?=Nemiro\UI\Html::CheckBox('checkbox1', 'anyvalue')?>
<input type="checkbox" name="checkbox1" id="checkbox1" value="anyvalue" />
With Label can be added caption to CheckBox.
<?=Nemiro\UI\Html::Label('click me', 'checkbox123')?>
<?=Nemiro\UI\Html::CheckBox('checkbox123', 'anyvalue')?>
<label for="checkbox123">click me</label>
<input type="checkbox" name="checkbox123" id="checkbox1" value="anyvalue" />
Note the identifier - checkbox123
, it is the same for Label and CheckBox.
To create a list of CheckBox, can be use the CheckBoxList method, which accepts the name of the group and a list of items.
The list is an array of elements, each element of which is an associative array containing the value
and title
of CheckBox.
<?=Nemiro\UI\Html::CheckBoxList
(
'myCheckboxList',
array
(
array('value' => '1', 'title' => 'First item'),
array('value' => '2', 'title' => 'Second item'),
array('value' => '3', 'title' => '...'),
array('value' => '123', 'title' => 'etc.')
)
)?>
<input type="checkbox" name="myCheckboxList[]" id="myCheckboxList0" value="1" />
<label for="myCheckboxList0">First item</label><br />
<input type="checkbox" name="myCheckboxList[]" id="myCheckboxList1" value="2" />
<label for="myCheckboxList1">Second item</label><br />
<input type="checkbox" name="myCheckboxList[]" id="myCheckboxList2" value="3" />
<label for="myCheckboxList2">...</label><br />
<input type="checkbox" name="myCheckboxList[]" id="myCheckboxList3" value="123" />
<label for="myCheckboxList3">etc.</label>
RadioButton very similar to the CheckBox.
Grouping RadioButton occurs named. For uniqueness, you can use an identifier that can be specified in the second parameter.
<?=Nemiro\UI\Html::RadioButton('gender', 'male')?>
<?=Nemiro\UI\Html::Label('Male', 'male')?>
<br />
<?=Nemiro\UI\Html::RadioButton('gender', 'female')?>
<?=Nemiro\UI\Html::Label('Female', 'female')?>
<hr />
<?=Nemiro\UI\Html::RadioButton('country', 'Russia')?>
<?=Nemiro\UI\Html::Label('Russia', 'Russia')?><br />
<?=Nemiro\UI\Html::RadioButton('country', 'China')?>
<?=Nemiro\UI\Html::Label('China', 'China')?><br />
<?=Nemiro\UI\Html::RadioButton('country', 'USA')?>
<?=Nemiro\UI\Html::Label('USA', 'USA')?><br />
<?=Nemiro\UI\Html::RadioButton('country', 'Germany')?>
<?=Nemiro\UI\Html::Label('Germany', 'Germany')?><br />
<?=Nemiro\UI\Html::RadioButton('country', 'France')?>
<?=Nemiro\UI\Html::Label('France', 'France')?>
<input type="radio" name="gender" id="male" value="true" />
<label for="male">Male</label><br />
<input type="radio" name="gender" id="female" value="true" />
<label for="female">Female</label>
<hr />
<input type="radio" name="country" id="Russia" value="true" />
<label for="Russia">Russia</label><br />
<input type="radio" name="country" id="China" value="true" />
<label for="China">China</label><br />
<input type="radio" name="country" id="USA" value="true" />
<label for="USA">USA</label><br />
<input type="radio" name="country" id="Germany" value="true" />
<label for="Germany">Germany</label><br />
<input type="radio" name="country" id="France" value="true" />
<label for="France">France</label>
The principle of constructing lists RadioButton is no different from similar lists CheckBox.
<?=Nemiro\UI\Html::RadioButtonList
(
'myRadioList',
array
(
array('value' => '1', 'title' => 'Meat'),
array('value' => '2', 'title' => 'Fish'),
array('value' => '3', 'title' => 'Green-fodder')
)
)?>
<input type="radio" name="myRadioList[]" id="myRadioList0" value="1" />
<label for="myRadioList0">Meat</label><br />
<input type="radio" name="myRadioList[]" id="myRadioList1" value="2" />
<label for="myRadioList1">Fish</label><br />
<input type="radio" name="myRadioList[]" id="myRadioList2" value="3" />
<label for="myRadioList2">Green-fodder</label>
Method TextBox allows to place a one-line text box. There are also methods for Password and Hidden.
<?=Nemiro\UI\Html::TextBox('textbox1', 'Hello world!')?><br />
<?=Nemiro\UI\Html::Password('password1', '123123')?>
<?=Nemiro\UI\Html::Hidden('hidden1', 'test')?>
<input type="text" name="textbox1" id="textbox1" value="Hello world!" /><br />
<input type="password" name="password1" id="password1" value="123123" />
<input type="hidden" name="hidden1" id="hidden1" value="test" />
To output multiline text fields can use the method TextArea.
<?=Nemiro\UI\Html::TextArea('textarea1', NULL, NULL, array('placeholder' => 'Default area', 'cols' => 50))?><br />
<?=Nemiro\UI\Html::TextArea('textarea2', NULL, 10, array('placeholder' => '10 rows area', 'cols' => 50))?>
<textarea name="textarea1" id="textarea1" placeholder="Default area" cols="50"></textarea><br />
<textarea name="textarea2" id="textarea2" rows="10" placeholder="10 rows area" cols="50"></textarea>
The DropDownList method creates a drop-down list.
List elements can be specified in the text array. For more complex lists, can be used an associative array, like for CheckBoxList or RadioButtonList.
<?=Nemiro\UI\Html::DropDownList
(
'country',
array
(
'Russia',
'Belarus',
'Kazakhstan',
'China',
'India',
'Brazil',
'Germany',
'Italy',
'France',
'United Kingdom',
'USA'
)
)?>
<?=Nemiro\UI\Html::DropDownList
(
'color',
array
(
array('value' => 'white', 'title' => 'White'),
array('value' => 'blue', 'title' => 'Blue', 'selected' => true),
array('value' => 'red', 'title' => 'Red')
)
)?>
<select name="country" id="country">
<option >Russia</option>
<option value="1">Belarus</option>
<option value="2">Kazakhstan</option>
<option value="3">China</option>
<option value="4">India</option>
<option value="5">Brazil</option>
<option value="6">Germany</option>
<option value="7">Italy</option>
<option value="8">France</option>
<option value="9">United Kingdom</option>
<option value="10">USA</option>
</select>
<select name="color" id="color">
<option value="white">White</option>
<option value="blue" selected="selected">Blue</option>
<option value="red">Red</option>
</select>
For multi-line listmay be used the ListBox method, which is completely the same as the DropDownList, but in addition accepts the number of rows displayed in the list.
<?=Nemiro\UI\Html::ListBox
(
'color', 5,
array
(
array('value' => 'white', 'title' => 'White'),
array('value' => 'blue', 'title' => 'Blue', 'selected' => true),
array('value' => 'red', 'title' => 'Red')
)
)?>
<select name="color" id="color">
<option value="white">White</option>
<option value="blue" selected="selected">Blue</option>
<option value="red">Red</option>
</select>
With Pagination method can be create a list of pages.
To place a list of the pages must specify current page number and total number of records.
<?=Nemiro\UI\Html::Pagination($_GET['page'], 50)?>
<ul class="pagination">
<li class="active"><a href="/elements.php?page=1">1</a></li>
<li><a href="/elements.php?page=2">2</a></li>
</ul>
You can specify an address to be used in the construction of the URL of a particular page. If the URL is not specified, it will use the address of the current page.
By default, any additional parameters will automatically be removed from the URL. This is to prevent generation of incorrect references through the list of pages. You can provide a list of parameter names that are allowed to use in the URL.