2017 © Pedro Peláez
 

library htselect

Generates the classic HTML Select field for choosing an option.

image

flsouto/htselect

Generates the classic HTML Select field for choosing an option.

  • Tuesday, February 28, 2017
  • by flsouto
  • Repository
  • 0 Watchers
  • 0 Stars
  • 18 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

HtSelect

This library can be used to generate <select> fields in an easy way. I recommend you take a look at the documentation of its parent classes in order to grasp all the functionality inherited by this particular one:, (*1)

Installation

Via composer:, (*2)

composer require flsouto/htselect

Usage

In the following example we generate a select field with three options., (*3)

<?php
require_once('vendor/autoload.php');
use FlSouto\HtSelect;

$select = new HtSelect("id_category");
$select->options([1=>'Category1',2=>'Category2',3=>'Category3']);

echo $select;

Outputs:, (*4)




Notice: the options method also accepts other formats besides an associative array. Take a look at the documentation of the HtChoice class in order to learn more., (*5)

Selecting an option

If you have read the documentation of the HtField and the HtWidget parent classes you already know that you are supposed to use the context method in order to set the value of a field/widget:, (*6)

<?php
require_once('vendor/autoload.php');
use FlSouto\HtSelect;

$select = new HtSelect('id_category');
$select->options([1=>'Category1',2=>'Category2',3=>'Category3']);
$select->context(['id_category'=>2]);

echo $select;

Outputs:, (*7)




Setting a caption

The "caption" is the default text which appears on the select field when no option has been selected yet. This is usally a message indicating that the user should choose something:, (*8)

<?php
require_once('vendor/autoload.php');
use FlSouto\HtSelect;

$select = new HtSelect('id_category');
$select->options([1=>'Category1',2=>'Category2',3=>'Category3']);
$select->caption('CHOOSE A CATEGORY:');

echo $select;

Outputs:, (*9)




Notice that by default the value "0" is used for the caption option. This means that when the form gets sent, if no option has been selected, then the "0" value will be sent as the category id, which in most cases would mean "no category". However, you can change that value if you want by using a second paramenter to the caption method:, (*10)

<?php
require_once('vendor/autoload.php');
use FlSouto\HtSelect;

$select = new HtSelect('id_category');
$select->options([1=>'Category1',2=>'Category2',3=>'Category3']);
$select->caption('CHOOSE A CATEGORY:', 'none'); # change value to 'none'

echo $select;

Outputs:, (*11)




The Versions

28/02 2017

dev-master

9999999-dev

Generates the classic HTML Select field for choosing an option.

  Sources   Download

The Requires

 

by Fabio Souto

html forms widgets options fields choices

28/02 2017

1.0.0

1.0.0.0

Generates the classic HTML Select field for choosing an option.

  Sources   Download

The Requires

 

by Fabio Souto

html forms widgets options fields choices