mvccore/ext-form-field-date

MvcCore - Extension - Form - Field - Date - form field types - input:date, input:datetime-local, input:time, input:week and input:month.

v5.3.0 2024-11-21 15:00 UTC

This package is auto-updated.

Last update: 2024-11-21 16:01:04 UTC


README

Latest Stable Version License PHP Version

MvcCore form extension with input field types date, datetime, time, week and month.

Installation

composer require mvccore/ext-form-field-date

Fields And Default Validators

  • input:date
    • Date
      • configured by default
      • validate submitted value format, min., max., step and dangerous characters
  • input:datetime-local (extended from input:date)
    • DateTime
      • configured by default
      • validate submitted value format, min., max., step and dangerous characters
  • input:time (extended from input:date)
    • Time
      • configured by default
      • validate submitted value format, min., max., step and dangerous characters
  • input:week (extended from input:date)
    • Week
      • configured by default
      • validate submitted value format, min., max., step and dangerous characters
  • input:month (extended from input:date)
    • Month
      • configured by default
      • validate submitted value format, min., max., step and dangerous characters

Features

  • always server side checked attributes required, disabled and readonly
  • all HTML5 specific and global atributes (by Mozilla Development Network Docs)
  • every field has it's build-in specific validator described above
  • every build-in validator adds form error (when necessary) into session and than all errors are displayed/rendered and cleared from session on error page, where user is redirected after submit
  • any field is possible to render naturally or with custom template for specific field class/instance
  • very extensible field classes - every field has public template methods:
    • SetForm() - called immediatelly after field instance is added into form instance
    • PreDispatch() - called immediatelly before any field instance rendering type
    • Render() - called on every instance in form instance rendering process
      • submethods: RenderNaturally(), RenderTemplate(), RenderControl(), RenderLabel() ...
    • Submit() - called on every instance when form is submitted

Examples

Basic Example

$form = (new \MvcCore\Ext\Form($controller))->SetId('demo');
...
$currentYear = intval(date("Y"));
$bornDate = new \MvcCore\Ext\Forms\Fields\Date();
$bornDate
	->SetName('born_date')
	->SetLabel('I was born:')
	//->SetFormat('Y-m-d') // not required, 'Y-m-d' by default
	->SetMin($currentYear - 130)
	->SetMax($currentYear);
$myMorningTime = new \MvcCore\Ext\Forms\Fields\Time([
	'name'		=> 'my_morning',
	'label'		=> 'I usually get up at morning at:',
	//'format'	=> 'H:i', // not required, 'H:i' by default
	'min'		=> '4:00',
	'max'		=> '10:00',
	'step'		=> 60 * 15, // 15 minutes
]);
...
$form->AddFields($bornDate, $myMorningTime);