Date selection in forms
With the help of the TUCAL datepicker a date selection can be easily realized. In order to create an input field that displays the date picker accordingly, the file php/datepicker.inc
must first be loaded at the top of the page:
<?php
…
# Use of the datepicker module
require_once('php/datepicker.inc');
seite(__FILE__);
?>
Security
It should be noted that this date selection only provides an alternative input. The user can still insert any content into the form. User input should always be verified on the server side.
Usage
Output can be provided with echo datepicker($settings)
.
The following parameters can be defined in the $settings
array:
value |
Initial value of the input (value ) as a string. Must be specified in the same format as set.
|
date_format |
Date format as string, combinations of the following characters can be passed:
dd.mm.yy
|
input_class |
CSS class of the inserted <input> element as string;
by default form-control
|
input_id |
ID of the inserted <input> element as string
|
input_name |
name attribute of the inserted <input> element as string
|
required |
Whether the inserted <input> element must be filled in (Boolean); Default true
|
Examples
general use
<?php
echo datepicker(
array(
"date_format" => "DD, 'the' d.m.yy",
"value" => "Wednesday, the 3.7.2019",
"required" => false
)
);
?>
accessible use
To provide a description for the input field, a
<label>
element can be used. This is assigned
to the input field via the defined ID. The description should contain
the purpose and the desired format of the input field.
<label for="dpExample">Desired date (in the format dd/mm/yyyy):</label>
<?php
echo datepicker(
array(
"date_format" => "dd/mm/yy",
"input_id" => "dpExample"
)
);
?>