Controls

Downloads
1.2.0
2016
Stable

This is a lightweight PHP library to render HTML controls, such as <input />, <button /> and <select>. It simplifies the process outputting HTML controls by providing functions that do all the boilerplate work.

Button and SubmitButton can either render an <input /> or a <button /> element by specifying a parameter respectively. DropDown takes an associative array to render the options list, where optgoups can be defined by using a key that starts with "optgroup", such as "optgroup1", "optgroup2", and so on.

Features

  • Lightweight
  • No ugly, repeating boilerplate or duplicated code
  • No need for htmlentities
  • All HTML input types including key features
  • Option to specify additional classes and HTML properties to the rendered element

Example

This example demonstrates some of the available controls. Here, the controls are automatically re-filled with the values from $_POST.

<?php
	include('bytecode77.controls.php');

	$roles =
	[
		'optgroup1' => 'Default roles',
		1 => 'Admin',
		2 => 'Moderator',
		3 => 'User',
		'optgroup2' => 'Other roles',
		4 => 'Guest'
	];
?>

<div>
	<!-- TextBox -->
	<?= Controls::TextBox('txtName', null, $_POST['txtName']) ?>

	<!-- Password TextBox -->
	<?= Controls::PasswordBox('txtPassword', null, $_POST['txtPassword']) ?>

	<!-- DropDown -->
	<?= Controls::DropDown('ddlRole', null, $roles, $_POST['ddlRole']) ?>

	<!-- CheckBox -->
	<?= Controls::CheckBox('chkRememberLogin', 'chkRememberLogin', isset($_POST['chkRememberLogin'])) ?>
	<?= Controls::CheckBoxLabel('chkRememberLogin', 'Remember Login') ?>

	<!-- RadioButton -->
	<?= Controls::RadioButton('radRole', null, 1, true) ?>
	<?= Controls::RadioButton('radRole', null, 2, true) ?>

	<!-- TextArea -->
	<?= Controls::TextArea('txtComment', null, $_POST['txtComment'], 10) ?>

	<!-- Button or SubmitButton -->
	<?= Controls::SubmitButton('btnLogin', null, 'Login') ?>
</div>