Viames Marino edited this page Oct 11, 2018 · 4 revisions

The Pair Form class is used to build HTML forms easily.

A Form object contains objects that inherit from the FormControl class because all controls have many properties and methods in common, for instance "name" property or render() method.

To create a form, you can proceed in this way using a smart ActiveRecord method:


use Pair\Form;
use Pair\Model;

class PersonsModel extends Model {

	public function getPersonFormByObject(Person $person) {

		// returns the Form object about a Person
		return $person->getForm();



In this example, the most important features of the Person object are interpreted and materialized in the properties of the automatically created form. For example, for an ActiveRecord object, a boolean property will become a checkbox in the form.

To customize the form, you can individually indicate each control that will be part of it:

public function getPersonForm() {
	// get all person groups
	$personGroups = PersonGroup::getAllObjects();

	// start the form
	$form = new Form();
	// add to all controls the form-control CSS class
	// ID control is hidden

	// add class default-select2 for JS event purposes
	$form->addSelect('personGroupId')->setListByObjectArray($personGroups, 'id', 'title')->addClass('default-select2');

	// a basic input text field		

	// email form input type

	// set this input as required

	return $form;
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.