Class: Zebra_Form_Date
source file: /includes/Date.php
Class Overview
XSS_Clean
|
--Zebra_Form_Control
|
--Zebra_Form_Date
Class for date controls.
Author(s):
Copyright:
- (c) 2006 - 2013 Stefan Gabos
Class methods
constructor __construct()
void
__construct (
string
$id
,
[
string
$default
= '']
,
[
array
$attributes
= '']
)
Adds a date control to the form.
Do not instantiate this class directly! Use the add() method instead! The output of this control will be a textbox control with an icon to the right of it. Clicking the icon will open an inline JavaScript date picker.
// create a new form
// add a date control to the form
$mydate = $form->add('date', 'my_date', date('Y-m-d'));
// set the date's format
// don't forget to always call this method before rendering the form
if ($form->validate()) {
// get the date in YYYY-MM-DD format so you can play with is easily
}
// output the form using an automatically generated template
$form->render();
Parameters:
| string |
$id |
Unique name to identify the control in the form. The control's name attribute will be the same as the id attribute! This is the name to be used when referring to the control's value in the POST/GET superglobals, after the form is submitted. This is also the name of the variable to be used in custom template files, in order to display the control. // in a template file, in order to print the generated HTML
// for a control named "my_date", one would use:
echo $my_date;
|
| string |
$default |
(Optional) Default date, formatted according to format. |
| array |
$attributes |
(Optional) An array of attributes valid for input controls (size, readonly, style, etc) Must be specified as an associative array, in the form of attribute => value. // setting the "readonly" attribute
$obj = $form->add(
'date',
'my_date',
'',
array(
'readonly' => 'readonly'
)
);
See set_attributes() on how to set attributes, other than through the constructor. The following attributes are automatically set when the control is created and should not be altered manually:
type, id, name, value, class |
Top
method always_show_clear()
void
always_show_clear (
)
Should the "Clear" button be always visible?
By default, the button for clearing a previously selected date is shown only if a previously selected date already exists; this means that if the input the date picker is attached to is empty, and the user selects a date for the first time, this button will not be visible; once the user picked a date and opens the date picker again, this time the button will be visible. The caption of the button can be changed in the Zebra_Form::language file. Setting this property to TRUE will make this button visible all the time.
Top
method always_visible()
void
always_visible (
string
$element
)
Should the date picker be always visible?
Setting this property to a jQuery element will result in the date picker being always visible, the indicated element acting as the date picker's container; Note that when this property is set to TRUE, the always_show_clear() will be automatically set to TRUE. $date = $form->add('date', 'my_date');
// an element having the ID "container"
// will be the date picker's container
Parameters:
| string |
$element |
A jQuery selector pointing to an existing element from the page to be used as the date picker's container. |
Top
method direction()
void
direction (
mixed
$direction
)
Direction of the calendar.
$obj = $form->add('date', 'mydate')
// calendar starts tomorrow and seven days after that are selectable
// calendar starts today and seven days after that are selectable
// calendar starts on January 1st 2013 and has no ending date
// (assuming "format" is YYYY-MM-DD)
// calendar ends today and starts on January 1st 2012
// assuming "format" is YYYY-MM-DD)
Parameters:
| mixed |
$direction |
A positive or negative integer: - n (a positive integer) creates a future-only calendar beginning at n days
after today;
- -n (a negative integer) creates a past-only calendar ending at n days
before today;
- if n is 0, the calendar has no restrictions.
Use boolean TRUE for a future-only calendar starting with today and use boolean FALSE for a past-only calendar ending today.You may also set this property to an array with two elements in the following combinations: - first item is boolean TRUE (calendar starts today), an integer > 0 (calendar
starts n days after today), or a valid date given in the format defined by
the "format" attribute (calendar starts at the specified date), and the second
item is boolean FALSE (the calendar has no ending date), an integer > 0 (calendar
ends n days after the starting date), or a valid date given in the format
defined by the "format" attribute and which occurs after the starting date
(calendar ends at the specified date)
- first item is boolean FALSE (calendar ends today), an integer < 0 (calendar
ends n days before today), or a valid date given in the format defined by the
"format" attribute (calendar ends at the specified date), and the second item
is an integer > 0 (calendar ends n days before the ending date), or a valid
date given in the format defined by the "format" attribute and which occurs
before the starting date (calendar starts at the specified date)
Note that disabled_dates() will still apply! Default is 0 (no restrictions). |
Top
method disabled_dates()
void
disabled_dates (
array
$disabled_dates
)
Disables selection of specific dates or range of dates in the calendar.
$obj = $form->add('date', 'mydate')
// disable January 1, 2012
$obj->disabled_date(array('1 1 2012'));
// disable all days in January 2012
$obj->disabled_date(array('* 1 2012'));
// disable January 1 through 10 in 2012
$obj->disabled_date(array('1-10 1 2012'));
// disable January 1 and 10 in 2012
$obj->disabled_date(array('1,10 1 2012'));
// disable 1 through 10, and then 20th, 22nd and 24th
// of January through March for every year
$obj->disabled_date(array('1-10,20,22,24 1-3 *'));
// disable all Saturdays and Sundays
$obj->disabled_date(array('* * * 0,6'));
// disable 1st and 2nd of July 2012,
// and all of August of 2012;
$obj->disabled_date(array('01 07 2012', '02 07 2012', '* 08 2012'));
Parameters:
| array |
$disabled_dates |
An array of strings representing disabled dates. Values in the string have to be in the following format: "day month year weekday" where "weekday" is optional and can be 0-6 (Saturday to Sunday); The syntax is similar to cron's syntax: the values are separated by spaces and may contain * (asterisk) - (dash) and , (comma) delimiters. Default is FALSE, no disabled dates. |
Top
method disable_zebra_datepicker()
void
disable_zebra_datepicker (
)
By default, Zebra_Form relies on Zebra_DatePicker for Date controls. If you want to use a different date picker, you have to disable the built-in one by calling this method.
Make sure the language used by the custom date picker is the same as the language() of the
library, or validation of the date will fail!
Also, note that format, direction and disabled dates
will still apply and will be taken into account when validating the date, but the other properties will be ignored
as are specific to Zebra_DatePicker!
Tags:
Top
method first_day_of_week()
void
first_day_of_week (
integer
$day
)
Week's starting day.
Parameters:
| integer |
$day |
Valid values are 0 to 6, Sunday to Saturday. Default is 1, Monday. |
Top
method format()
void
format (
string
$format
)
Sets the format of the returned date.
Parameters:
| string |
$format |
Format of the returned date. Accepts the following characters for date formatting: d, D, j, l, N, w, S, F, m, M, n, Y, y borrowing syntax from (PHP's date function) Note that when setting a date format without days (‘d’, ‘j’), the users will be able to select only years and months, and when setting a format without months and days (‘F’, ‘m’, ‘M’, ‘n’, ‘t’, ‘d’, ‘j’), the users will be able to select only years. Also note that the value of the "view" property (see below) may be overridden if it is the case: a value of "days" for the "view" property makes no sense if the date format doesn’t allow the selection of days. Default format is Y-m-d |
Top
method get_date()
string
get_date (
)
To be used after the form is submitted!
Returns submitted date in the YYYY-MM-DD format so that it's directly usable with a database engine or with PHP's strtotime function.
Tags:
| return: |
Returns submitted date in the YYYY-MM-DD format, or an empty string if control was submitted with no value (empty). |
Top
method inside()
void
inside (
boolean
$value
)
Sets whether the icon for opening the datepicker should be inside or outside the element.
Parameters:
| boolean |
$value |
If set to FALSE, the icon will be placed to the right of the parent element, while if set to TRUE it will be placed to the right of the parent element, but *inside* the element itself. Default TRUE. |
Top
method offset()
void
offset (
array
$value
)
Sets the offset, in pixels (x, y), to shift the date picker’s position relative to the top-left of the icon that toggles the date picker.
Parameters:
| array |
$value |
An array indicating the offset, in pixels (x, y), to shift the date picker’s position relative to the top-left of the icon that toggles the date picker. Default is array(20, -5). |
Top
method pair()
void
pair (
string
$value
)
Pairs the date element with another date element from the page, so that the other date element will use the current date element’s value as starting date.
// let's assume this will be the starting date
$date1 = $form->add('date', 'starting_date');
// dates are selectable in the future, starting with today
// indicate another date element that will use this
// element's value as starting date
$date1->pair('ending_date');
// the other date element
$date2 = $form->add('date', 'ending_date');
// start one day after the reference date
// (that is, one day after whaterver is selected in the first element)
Parameters:
| string |
$value |
The ID of another "date" element which will use the current date element's value as starting date. Note that the rules set in the "direction" property will still apply, only that the reference date will not be the current system date but the value selected in the current date picker. Default is FALSE (not paired with another date picker) |
Top
method readonly_element()
void
readonly_element (
boolean
$value
)
Sets whether the element the calendar is attached to should be read-only.
Parameters:
| boolean |
$value |
The setting's value If set to TRUE, a date can be set only through the date picker and cannot be enetered manually. Default is TRUE. |
Top
method show_week_number()
void
show_week_number (
string
$value
)
Sets whether an extra column should be shown, showing the number of each week.
Parameters:
| string |
$value |
Anything other than FALSE will enable this feature, and use the given value as column title. For example, show_week_number: ‘Wk’ would enable this feature and have "Wk" as the column’s title. Default is FALSE. |
Top
method start_date()
void
start_date (
date
$value
)
Sets a default date to start the date picker with.
Parameters:
| date |
$value |
A default date to start the date picker with, Must be specified in the format defined by the "format" property, or it will be ignored! Note that this value is used only if there is no value in the field the date picker is attached to! Default is FALSE. |
Top
method toHTML()
string
toHTML (
)
Generates the control's HTML code.
This method is automatically called by the render() method!
Tags:
| return: |
The control's HTML code |
Top
method view()
void
view (
string
$view
)
Sets how should the date picker start.
Parameters:
| string |
$view |
How should the date picker start. Valid values are "days", "months" and "years". Note that the date picker is always cycling days-months-years when clicking in the date picker's header, and years-months-days when selecting dates (unless one or more of the views are missing due to the date's format) Also note that the value of the "view" property may be overridden if the date's format requires so! (i.e. "days" for the "view" property makes no sense if the date format doesn't allow the selection of days) Default is "days". |
Top
method weekend_days()
void
weekend_days (
array
$days
)
Sets the days of the week that are to be considered as "weekend days".
Parameters:
| array |
$days |
An array of days of the week that are to be considered as "weekend days". Valid values are 0 to 6 (Sunday to Saturday). Default is array(0,6) (Saturday and Sunday). |
Top
method zero_pad()
void
zero_pad (
boolean
$state
)
Should day numbers < 10 be padded with zero?
Parameters:
| boolean |
$state |
When set to TRUE, day numbers < 10 will be prefixed with 0. Default is FALSE. |
Top
|