Jump to main content
University Computer Centre
Date selection in forms

Date selection in forms

  1. Usage
  2. Examples
    1. general use
    2. accessible use

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:
  • d: day of the month without leading zero
  • dd: day of the month as two-digit number
  • o: day of the year without leading zero
  • oo: day of the year as a three-digit number
  • D: short name of the day
  • DD: name of the day
  • m: month of the year without leading zero
  • mm: month of the year as a two-digit number
  • M: short name of the month
  • MM: name of the month
  • y: year as a two-digit number
  • yy: year as a four-digit number
  • '...': text
  • '': single quotation mark
Default: 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"
    )
);

?>