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.2.5 2024-02-19 15:46 UTC

This package is auto-updated.

Last update: 2024-10-19 17:31:01 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);