Package: Controls

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

Inherited methods

Class: Zebra_Form_Control

Zebra_Form_Control::change_case()
Call this method to instruct the script to force all letters typed by the user, to either uppercase or lowercase, in real-time.
Zebra_Form_Control::disable_xss_filters()
Disables XSS filtering of the control's submitted value.
Zebra_Form_Control::get_attributes()
Returns the values of requested attributes.
Zebra_Form_Control::get_submitted_value()
Returns the control's value after the form was submitted.
Zebra_Form_Control::lock()
Locks the control's value. A locked control will preserve its default value after the form is submitted even if the user altered it.
Zebra_Form_Control::reset()
Resets the control's submitted value (empties text fields, unchecks radio buttons/checkboxes, etc).
Zebra_Form_Control::set_attributes()
Sets one or more of the control's attributes.
Zebra_Form_Control::set_rule()
Sets a single or an array of validation rules for the control.

Class: XSS_Clean

XSS_Clean::sanitize()
Sanitizes submitted data so that Cross Site Scripting Hacks can be prevented.

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.

  1.  //  create a new form
  2.  $form new Zebra_Form('my_form');
  3.  
  4.  /**
  5.   *  add a date control to the form
  6.   *  the "&" symbol is there so that $obj will be a reference to the object in PHP 4
  7.   *  for PHP 5+ there is no need for it
  8.   */
  9.  $obj &$form->add('date''my_date'date('Y-m-d'));
  10.  
  11.  //  set the date's format
  12.  $obj->format('Y-m-d');
  13.  
  14.  // don't forget to always call this method before rendering the form
  15.  if ($form->validate()) {
  16.      // put code here
  17.  }
  18.  
  19.  //  output the form using an automatically generated template
  20.  $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.

  1.  /**
  2.   *  in a template file, in order to print the generated HTML
  3.   *  for a control named "my_date", one would use:
  4.   */
  5.  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.

  1. //  setting the "readonly" attribute
  2. $obj &$form->add(
  3.     'date',
  4.     'my_date',
  5.     '',
  6.     array(
  7.         'readonly' => 'readonly'
  8.     )
  9. );

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