Login Retreive lost passwordRegister
Search

Manual  /  Functions  /  Fields  /  DateField

DateField
DateField (
string $title
string $name
mixed $validator = null,
boolean $required = true,
string $mask = "d-m-y",
mixed $interval = 90,
string $extra = null 
)

Arguments:

Name Description
$title Title of the field
$name Name of the field
$validator This can either be the name of your own validation function or the constant name of a predefined validator function. For more information about validators see Validators.
It is also possible to use a method as a validation function. In this case you should pass an array where the first item is the object and the second item the name of the method.

(NOTE: the date is automaticly checked for a correct day-month-year combination)
$required When the field is required, the user has to select something. If the field is not required, the user can select empty values.
$mask The mask which will be used to lay out the date fields. If no mask is given, the default mask is loaded which is set in the config file with the var FH_DATEFIELD_DEFAULT_DISPLAY.

In the mask the following placeholders are replaced:
  • d = selectfield day

  • m = selectfield month

  • y = selectfield year

  • D = textfield day

  • M = textfield month

  • Y = textfield year

The date will be changed to the correct format when it's being saved into the database. The date will have the same format as given in the mask when it's returned to the user (in your onSaved or OnCorrect function)
$interval The interval between the current year and the years to start/stop. By default, the years are starting at 90 yeas from now. It is also possible to have years in the future. This is done like this: "90:10" (10 years in the future).
$extra This can be extra information which will be included in the fields html tag. You can add for example some CSS or javascript.

Description:

This function generates a DateField.

Example

<?php 

// include the class 
include('FH3/class.FormHandler.php'); 

// make a new $form object 
$form = new FormHandler(); 

// make the datefield 
$form -> dateField("Birthdate""birthdate"); 

// button beneath it 
$form -> submitButton("Save"); 

// set the 'commit after form' function 
$form -> onCorrect("doRun"); 

// send the form to the screen 
$form -> flush(); 

// the function witch handles the code after the form 
function doRun($data

   
// show the birthdate 
   
echo "Your birthday is "$data["birthdate"]; 


?>

Preview image

preview image

See also: jsDateField  |  TimeField  |  DateTextField  |  jsDateTextField

Latest change: 11 July 11 / 09:27

Comments

Teye Heimans 03 November 07 / 09:59  
It is also possible with the interval to set the years from like 1900 till 1980 (so not untill the current date). You can just use a negative number like this:

"90:-10"

Teye Heimans 30 June 08 / 11:50  
There is a small bug in the datefield and the database formhandler.

I wanted the user to select only a month and year. I added the day option with addValue (first day of month), like this:

<?php

$form 
-> dateField('Release month''release'nulltrue'm-y');

$d $form -> getValue('release');
if( !empty( 
$d ))
{
    list( 
$m$y ) = explode'-'$form -> getValue('release') );
    
$form -> addValue('release'"$y-$m-01");
}

?>

powered by PHP-GLOBE   © 2004 - 2024 FormHandler. All rights reserved.   -   Open source license