Thứ Năm, 24 tháng 4, 2014

HTML5 input elements [HTML5 Support]

Zend Framework 2.0 now supports all of the newly specified HTML5 input types; these inputs aravailable under Zend\Form\Element like any other input types. The following table describes each of these elements along with their class names:

datetime         ‹    Element: Zend\Form\Element\DateTime
      Used trender the Date/Time Elemeninput field with the time zone setUTC
      HTML tag: <input type="datetime" name="element- date-time">
      The datetime elemenrendered in Opera 12.0 is shown in the following screenshot:


datetime-local   ‹    Element: Zend\Form\Element\DateTimeLocal
      Used trender the Date/Time Local Elemeninput field for the client browser's time zone
      HTML tag: <input type="datetime-local" name="element-date-time-local">
      The datetime-local elemenrendered in Opera 12.0 is shown in the following screenshot:


Input type                     Description
time             ‹    Element: Zend\Form\Element\Time
      Used trender the Time Elemenfield
      HTML tag: <input type="time" name="element-time">
      The time elemenrendered in Opera 12.0 is shown in the following screenshot:


date             ‹    Element: Zend\Form\Element\Date
      Used trender the Date Elemenfield
      HTML tag: <input type="date" name="element-date">
      The date elemenrendered in Opera 12.0 is shown in the following screenshot:


week             ‹    Element: Zend\Form\Element\Week
      Used trender the Week Elemenfield
      HTML tag: <input type="week" name="element-week">
      The week elemenrendered in Opera 12.0 is shown in the following screenshot:


month            ‹    Element: Zend\Form\Element\Month
      Used trender the Month Elemenfield
      HTML tag: <input type="month" name="element- month">
      The month elemenrendered in Opera 12.0 is shown in the following screenshot:


email            ‹    Element: Zend\Form\Element\Email
      Used trender the Email input field
      HTML tag: <input type="email" name="element- email">
url              ‹    Element: Zend\Form\Element\Url
      Used trender the URL input field
      HTML tag: <input type="url" name="element-url"> number   ‹    Element: Zend\Form\Element\Number
      Used trender the Number Elemeninput field
      HTML tag: <input type="number" name="element- number">
      The number elemenrendered in Opera 12.0 is shown in the following screenshot:


range            ‹    Element: Zend\Form\Element\Range
      Used trender the Range Elemeninput field using slider control
      HTML tag: <input type="range" name="element- range">
      The range elemenrendered in Opera 12.0 is shown in the following screenshot:


color            ‹    Element: Zend\Form\Element\Color
      Used trender the Color Elemeninput field with a color picker
      HTML tag: <input type="color" name="element- color">
      The color elemenrendered in Opera 12.0 is shown in the following screenshot:


In this example we will be creating test HTML5 form for rendering various types of HTML5 input elements:

1.       Create a test action for rendering the form elemenformAction(); it can be created under the necontroller Html5TestController                  - module/Users/ src/Users/Controller/Html5TestController.php.
2.       Add references tZend\Form\Form and Zend\Form\Element:
use Zend\Form\Element; use Zend\Form\Form;
3.       Add various HTML5 form elements to the form:
$form  = new Form();

// Date/Time Element
$dateTime = new Element\DateTime('element-date-time');
$dateTime
->setLabel('Date/Time Element')
->setAttributes(array(
'min'  => '2000-01-01T00:00:00Z',
'max'  => '2020-01-01T00:00:00Z', 'step' => '1',
));


$form->add($dateTime);

// Date/Time Local Element
$dateTime = new Element\DateTimeLocal('element-date-time-local');
$dateTime
->setLabel('Date/Time Local Element')
->setAttributes(array(
'min'  => '2000-01-01T00:00:00Z',
'max'  => '2020-01-01T00:00:00Z', 'step' => '1',
));
$form->add($dateTime);

// Time Element
$time = new Element\Time('element-time');
$time->setLabel('Time Element');
$form->add($time);

// Date Element
$date = new Element\Date('element-date');
$date
->setLabel('Date Element')
->setAttributes(array( 'min'  => '2000-01-01', 'max'  => '2020-01-01', 'step' => '1',
));
$form->add($date);

// Week Element
$week = new Element\Week('element-week');
$week->setLabel('Week Element');
$form->add($week);

// Month Element
$month = new Element\Month('element-month');
$month->setLabel('Month Element');
$form->add($month);

// Email Element
$email = new Element\Email('element-email');
$email->setLabel('Email Element');


$form->add($email);

// URL Element
$url = new Element\Url('element-url');
$url->setLabel('URL Element');
$form->add($url);

// Number Element
$number = new Element\Number('element-number');
$number->setLabel('Number Element');
$form->add($number);

// Range Element
$range = new Element\Range('element-range');
$range->setLabel('Range Element');
$form->add($range);

// Color Element
$color = new Element\Color('element-color');
$color->setLabel('Color Element');
$form->add($color);


What just happened?
We have created a simple form purely using HTML5 elements that are supported bZend Framework 2.0. The form in its current shape can be rendered by creating the necessary view. Our nextask will be to build the viefor this form with the use of HTML5 helpers and render all the form elements thawere added to the form.

Không có nhận xét nào:

Đăng nhận xét