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 - 2012 Stefan Gabos
Class methods
constructor Zebra_Form_Date()
void
Zebra_Form_Date (
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
* the "&" symbol is there so that $obj will be a reference to the object in PHP 4
* for PHP 5+ there is no need for it
*/
$obj =
&$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()) {
// put code here
}
// 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 was submitted. This is also the name of the variable to be used in the template file, containing the generated HTML for 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 direction()
void
direction (
mixed
$direction
)
Direction of the calendar.
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.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.
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: array('1 1 2012') would disable January 1, 2012; array('* 1 2012') would disable all days in January 2012; array('1-10 1 2012') would disable January 1 through 10 in 2012; array('1,10 1 2012') would disable January 1 and 10 in 2012; array('1-10,20,22,24 1-3 *') would disable 1 through 10, plus the 22nd and 24th of January through March for every year; array('* * * 0,6') would disable all Saturdays and Sundays; Default is FALSE, no disabled dates. |
Top
method first_day_of_the_week()
void
first_day_of_the_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) Default format is Y-m-d |
Top
method get_date()
string
get_date (
)
To be used after the form was 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 readonly_element()
void
readonly_element (
boolean
$value
)
Sets wether 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 toHTML()
string
toHTML (
)
Returns the generated HTML code for the control.
This method is automatically called by the render() method!
Tags:
| return: |
The generated HTML code for the control |
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". 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