/** * Adds a CAPTCHA image to the form. * * <b>Do not instantiate this class directly! Use the {@link Zebra_Form::add() add()} method instead!</b> * * <b>You must also place a {@link Zebra_Form_Text textbox} control on the form and set the "captcha" rule to it! * (through {@link set_rule()})</b> * * Properties of the CAPTCHA image can be altered by editing the file includes/captcha.php. * * By default, captcha values are triple md5 hashed and stored in cookies, and when the user enters the captcha * value the value is also triple md5 hashed and the two values are then compared. Sometimes, your users may have * a very restrictive cookie policy and so cookies will not be set, and therefore they will never be able to get * past the CAPTCHA control. If it's the case, call the {@link Zebra_Form::captcha_storage() captcha_storage} * method and set the storage method to "session". * * <code> * // create a new form * $form = new Zebra_Form('my_form'); * * // add a CAPTCHA image * $form->add('captcha', 'my_captcha', 'my_text'); * * // add a label for the textbox * $form->add('label', 'label_my_text', 'my_text', 'Are you human?'); * * // add a CAPTCHA to the form * $obj = $form->add('text', 'my_text'); * * // set the "captcha" rule to the textbox * $obj->set_rule(array( * 'captcha' => array('error', 'Characters not entered correctly!') * )); * * // 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(); * </code> * * @param string $id Unique name to identify the control in the form. * * This is the name of the variable to be used in the template file, containing * the generated HTML for the control. * * <code> * // in a template file, in order to print the generated HTML * // for a control named "my_captcha", one would use: * echo $my_captcha; * </code> * * @param string $attach_to The <b>id</b> attribute of the {@link Zebra_Form_Text textbox} control to attach * the CAPTCHA image to. * * @return void */ function __construct($id, $attach_to, $storage = 'cookie') { // call the constructor of the parent class parent::__construct(); // set the private attributes of this control // these attributes are private for this control and are for internal use only // and will not be rendered by the _render_attributes() method $this->private_attributes = array('disable_xss_filters', 'for', 'locked'); // set the default attributes for the text control // put them in the order you'd like them rendered $this->set_attributes(array('type' => 'captcha', 'name' => $id, 'id' => $id, 'for' => $attach_to)); }
/** * Adds an <input type="hidden"> control to the form. * * <b>Do not instantiate this class directly! Use the {@link Zebra_Form::add() add()} method instead!</b> * * <code> * // create a new form * $form = new Zebra_Form('my_form'); * * // add a hidden control to the form * $obj = $form->add('hidden', 'my_hidden', 'Secret value'); * * // 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(); * </code> * * @param string $id Unique name to identify the control in the form. * * The control's <b>name</b> attribute will be the same as the <b>id</b> 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. * * <b>Hidden controls are automatically rendered when the {@link Zebra_Form::render() render()} * method is called!</b><br> * <b>Do not print them in template files!</b> * * @param string $default (Optional) Default value of the text box. * * @return void */ function __construct($id, $default = '') { // call the constructor of the parent class parent::__construct(); // set the private attributes of this control // these attributes are private for this control and are for internal use only // and will not be rendered by the _render_attributes() method $this->private_attributes = array('disable_xss_filters', 'locked'); // set the default attributes for the hidden control // put them in the order you'd like them rendered // notice that if control's name is 'MAX_FILE_SIZE' we'll generate a random ID attribute for the control // as, with multiple forms having upload controls on them, this hidden control appears as many times as the // forms do and we don't want to have the same ID assigned to multiple controls $this->set_attributes(array('type' => 'hidden', 'name' => $id, 'id' => $id != 'MAX_FILE_SIZE' ? $id : 'mfs_' . rand(0, 100000), 'value' => $default)); }
/** * Adds an <input type="reset"> control to the form. * * <b>Do not instantiate this class directly! Use the {@link Zebra_Form::add() add()} method instead!</b> * * <code> * // create a new form * $form = new Zebra_Form('my_form'); * * // add a reset control to the form * $obj = $form->add('reset', 'my_reset', 'Reset'); * * // 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(); * </code> * * @param string $id Unique name to identify the control in the form. * * The control's <b>name</b> attribute will be the same as the <b>id</b> 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. * * <code> * // in a template file, in order to print the generated HTML * // for a control named "my_reset", one would use: * echo $my_reset; * </code> * * @param string $caption Caption of the reset button control. * * @param array $attributes (Optional) An array of attributes valid for * {@link http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.4 input} * controls (size, readonly, style, etc) * * Must be specified as an associative array, in the form of <i>attribute => value</i>. * <code> * // setting the "alt" attribute * $obj = $form->add( * 'reset', * 'my_reset', * 'Reset', * array( * 'alt' => 'Click to reset values' * ) * ); * </code> * * See {@link Zebra_Form_Control::set_attributes() 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:<br> * <b>type</b>, <b>id</b>, <b>name</b>, <b>value</b>, <b>class</b> * * @return void */ function __construct($id, $caption, $attributes = '') { // call the constructor of the parent class parent::__construct(); // set the private attributes of this control // these attributes are private for this control and are for internal use only // and will not be rendered by the _render_attributes() method $this->private_attributes = array('disable_xss_filters', 'locked'); // set the default attributes for the reset button control // put them in the order you'd like them rendered $this->set_attributes(array('type' => 'reset', 'name' => $id, 'id' => $id, 'value' => $caption, 'class' => 'reset')); // if "class" is amongst user specified attributes if (is_array($attributes) && isset($attributes['class'])) { // we need to set the "class" attribute like this, so it doesn't overwrite previous values $this->set_attributes(array('class' => $attributes['class']), false); // make sure we don't set it again below unset($attributes['class']); } // sets user specified attributes for the control $this->set_attributes($attributes); }
/** * Adds a time picker control to the form. * * <b>Do not instantiate this class directly! Use the {@link Zebra_Form::add() add()} method instead!</b> * * The output of this control will be one, two, three or four {@link Zebra_Form_Select select} controls for hour, * minutes, seconds and AM/PM respectively, according to the given format as set by the <i>$attributes</i> argument. * * Note that even though there will be more select boxes, the submitted values will be available as a single merged * value (in the form of hh:mm:ss AM/PM, depending on the format), with the name as given by the <i>id</i> argument. * * <code> * // create a new form * $form = new Zebra_Form('my_form'); * * // add a time picker control for hour and minutes * $obj = $form->add('time', 'my_time', date('H:i'), array('format' => 'hm')); * * // don't forget to always call this method before rendering the form * if ($form->validate()) { * * // note that even though there will be more select boxes, the submitted * // values will be available as a single merged value (in the form of * // mm:mm:ss AM/PM, depending on the format), with the name as given by * // the "id" argument: * echo $_POST['my_time']; * * } * * // output the form using an automatically generated template * $form->render(); * </code> * * @param string $id Unique name to identify the control in the form. * * The control's <b>name</b> attribute will be the same as the <b>id</b> 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. * * <code> * // in a template file, in order to print the generated HTML * // for a control named "my_time", one would use: * echo $my_time; * </code> * * @param string $default (Optional) String representing the default time to be shown. Must be set according * to the format of the time, as specified in <i>$attributes</i>. For example, for a * time format of "hm", one would set the default time in the form of "hh:mm" while * for a time format of "hms", one would set the time in the form of "hh:mm:ss". * * Default is current system time. * * @param array $attributes (Optional) An array of user specified attributes valid for an time picker * control (format, hours, minutes, seconds, am/pm). * * Must be specified as an associative array, in the form of <i>attribute => value</i>. * * Available attributes are: * * - format - format of time; a string containing one, or a combination of the four * allowed characters: "h" (hours), "m" (minutes) and "s" (seconds) and "g" for * using 12-hours format instead of the default 23-hours format; (i.e. setting the * format to "hm" would allow the selection of hours and minutes, setting the * format to "hms" would allow the selection of hours, minutes and seconds, and * setting the format to "hmg" would allow the selection of hours and minutes * using the 12-hours format instead of the 24-hours format) * * - hours - an array of selectable hours (i.e. array(10, 11, 12)) * * - minutes - an array of selectable minutes (i.e. array(15, 30, 45)) * * - seconds - an array of selectable seconds * * See {@link Zebra_Form_Control::set_attributes() set_attributes()} on how to set * attributes, other than through the constructor. * * @return void */ function __construct($id, $default = '', $attributes = '') { // call the constructor of the parent class parent::__construct(); // these will hold the default selectable hours, minutes and seconds $hours = $minutes = $seconds = array(); // all the 24 hours are available by default for ($i = 0; $i < 24; $i++) { $hours[] = $i; } // all the minutes and seconds are available by default for ($i = 0; $i < 60; $i++) { $minutes[] = $seconds[] = $i; } // set the private attributes of this control // these attributes are private for this control and are for internal use only // and will not be rendered by the _render_attributes() method $this->private_attributes = array('disable_xss_filters', 'locked', 'type', 'name', 'id', 'format', 'hours', 'minutes', 'seconds', 'value'); // set the default attributes for the text control // put them in the order you'd like them rendered $this->set_attributes(array('type' => 'time', 'name' => $id, 'id' => $id, 'value' => $default, 'class' => 'control time', 'format' => 'hm', 'hours' => $hours, 'minutes' => $minutes, 'seconds' => $seconds)); // sets user specified attributes for the control $this->set_attributes($attributes); }
/** * Add an <label> control to the form. * * <b>Do not instantiate this class directly! Use the {@link Zebra_Form::add() add()} method instead!</b> * * <code> * // create a new form * $form = new Zebra_Form('my_form'); * * // add a label, attached to a textbox control * $form->add('label', 'label_my_text', 'my_text', 'Enter some text:'); * * // add a text control to the form * $obj = $form->add('text', 'my_text'); * * // 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(); * </code> * * @param string $id Unique name to identify the control in the form. * * This is the name of the variable to be used in the template file, containing * the generated HTML for the control. * * <code> * // in a template file, in order to print the generated HTML * // for a control named "my_label", one would use: * echo $my_label; * </code> * * @param string $attach_to The <b>id</b> attribute of the control to attach the note to. * * <i>Notice that this must be the "id" attribute of the control you are attaching * the label to, and not the "name" attribute!</i> * * This is important as while most of the controls have their <b>id</b> attribute * set to the same value as their <b>name</b> attribute, for {@link Zebra_Form_Checkbox checkboxes}, * {@link Zebra_Form_Select selects} and {@link Zebra_Form_Radio radio buttons} this * is different. * * <b>Exception to the rule:</b> * * Just like in the case of {@link Zebra_Form_Note notes}, if you want a <b>master</b> * label, a label that is attached to a <b>group</b> of checkboxes/radio buttons * rather than individual controls, this attribute must instead refer to the <b>name</b> * of the controls (which, for groups of checkboxes/radio buttons, is one and the same). * This is important because if the group of checkboxes/radio buttons have the * <i>required</i> rule set, this is the only way in which the "required" symbol * (the red asterisk) will be attached to the master label instead of being attached * to the first checkbox/radio button from the group. * * @param mixed $caption Caption of the label. * * <i>Putting a $ (dollar) sign before a character will turn that specific character into * the accesskey.</i><br> * <i>If you need the dollar sign in the label, escape it with</i> \ <i>(backslash)</i> * * @param array $attributes (Optional) An array of attributes valid for * {@link http://www.w3.org/TR/REC-html40/interact/forms.html#edef-LABEL label} * elements (style, etc) * * Must be specified as an associative array, in the form of <i>attribute => value</i>. * <code> * // setting the "style" attribute * $obj = $form->add( * 'label', * 'label_my_text', * 'my_text', * 'My Label:' * array( * 'style' => 'font-weight: normal' * ) * ); * </code> * * <b>Special attribute:</b> * * When setting the special attribute <b>inside</b> to <b>true</b>, the label will * appear inside the control is attached to (if the control the label is attached to * is a {@link Zebra_Form_Text textbox} or a {@link Zebra_Form_Textarea textarea}) and * will disappear when the control will receive focus. When the "inside" attribute is * set to TRUE, the label will not be available in the template file as it will be * contained by the control the label is attached to! * * <code> * $form->add('label', 'my_label', 'my_control', 'My Label:', array('inside' => true)); * </code> * * <samp>Sometimes, when using floats, the inside-labels will not be correctly positioned * as jQuery will return invalid numbers for the parent element's position; If this is * the case, make sure you enclose the form in a div with position:relative to fix * this issue.</samp> * * See {@link Zebra_Form_Control::set_attributes() 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:<br> * <b>id</b>, <b>for</b> * * @return void */ function __construct($id, $attach_to, $caption, $attributes = '') { // call the constructor of the parent class parent::__construct(); // set the private attributes of this control // these attributes are private for this control and are for internal use only // set the private attributes of this control // these attributes are private for this control and are for internal use only $this->private_attributes = array('disable_xss_filters', 'for_group', 'inside', 'label', 'locked', 'name', 'type'); // set the default attributes for the label $this->set_attributes(array('for' => $attach_to, 'id' => $id, 'label' => $caption, 'name' => $id, 'type' => 'label')); // sets user specified attributes for the table cell $this->set_attributes($attributes); }
/** * Adds a "note" to the form, attached to a control. * * <b>Do not instantiate this class directly! Use the {@link Zebra_Form::add() add()} method instead!</b> * * <code> * // create a new form * $form = new Zebra_Form('my_form'); * * // add a text control to the form * $obj = $form->add('text', 'my_text'); * * // attach a note to the textbox control * $form->add('note', 'note_my_text', 'my_text', 'Enter some text in the field above'); * * // 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(); * </code> * * @param string $id Unique name to identify the control in the form. * * This is the name of the variable to be used in the template file, containing * the generated HTML for the control. * * <code> * // in a template file, in order to print the generated HTML * // for a control named "my_note", one would use: * echo $my_note; * </code> * * @param string $attach_to The <b>id</b> attribute of the control to attach the note to. * * <i>Notice that this must be the "id" attribute of the control you are attaching * the label to, and not the "name" attribute!</i> * * This is important as while most of the controls have their <b>id</b> attribute * set to the same value as their <b>name</b> attribute, for {@link Zebra_Form_Checkbox checkboxes}, * {@link Zebra_Form_Select selects} and {@link Zebra_Form_Radio radio buttons} this * is different. * * <b>Exception to the rule:</b> * * Just like in the case of {@link Zebra_Form_Label labels}, if you want a <b>master</b> * note, a note that is attached to a <b>group</b> of checkboxes/radio buttons rather than * individual controls, this attribute must instead refer to the <b>name</b> of the * controls (which, for groups of checkboxes/radio buttons, is one and the same). * * @param string $caption Content of the note (can be both plain text and/or HTML) * * @param array $attributes (Optional) An array of attributes valid for * {@link http://www.w3.org/TR/REC-html40/struct/global.html#h-7.5.4 div} * elements (style, etc) * * Must be specified as an associative array, in the form of <i>attribute => value</i>. * <code> * // setting the "style" attribute * $obj = $form->add( * 'note', * 'note_my_text', * 'my_text', * array( * 'style' => 'width:250px' * ) * ); * </code> * * See {@link Zebra_Form_Control::set_attributes() 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:<br> * <b>class</b> * * @return void */ function __construct($id, $attach_to, $caption, $attributes = '') { // call the constructor of the parent class parent::__construct(); // set the private attributes of this control // these attributes are private for this control and are for internal use only $this->private_attributes = array('caption', 'disable_xss_filters', 'locked', 'for', 'name', 'type'); // set the default attributes for the HTML control $this->set_attributes(array('class' => 'note', 'caption' => $caption, 'for' => $attach_to, 'id' => $id, 'name' => $id, 'type' => 'note')); // if "class" is amongst user specified attributes if (is_array($attributes) && isset($attributes['class'])) { // we need to set the "class" attribute like this, so it doesn't overwrite previous values $this->set_attributes(array('class' => $attributes['class']), false); // make sure we don't set it again below unset($attributes['class']); } // sets user specified attributes for the control $this->set_attributes($attributes); }
/** * Adds a date control to the form. * * <b>Do not instantiate this class directly! Use the {@link Zebra_Form::add() add()} method instead!</b> * * The output of this control will be a {@link Zebra_Form_Text textbox} control with an icon to the right of it.<br> * Clicking the icon will open an inline JavaScript date picker.<br> * * <code> * // create a new form * $form = new Zebra_Form('my_form'); * * // add a date control to the form * $mydate = $form->add('date', 'my_date', date('Y-m-d')); * * // you *have* to set the "date" rule * $mydate->set_rule(array( * 'date' => array('error', 'Invalid date specified!'), * )); * * // set the date's format * $mydate->format('M d, Y'); * * // 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 * $date = $mydate->get_date(); * * } * * // output the form using an automatically generated template * $form->render(); * </code> * * @param string $id Unique name to identify the control in the form. * * The control's <b>name</b> attribute will be the same as the <b>id</b> 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. * * <code> * // in a template file, in order to print the generated HTML * // for a control named "my_date", one would use: * echo $my_date; * </code> * * @param string $default (Optional) Default date, formatted according to {@link format() format}. * * @param array $attributes (Optional) An array of attributes valid for * {@link http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.4 input} * controls (size, readonly, style, etc) * * Must be specified as an associative array, in the form of <i>attribute => value</i>. * <code> * // setting the "readonly" attribute * $obj = $form->add( * 'date', * 'my_date', * '', * array( * 'readonly' => 'readonly' * ) * ); * </code> * * See {@link Zebra_Form_Control::set_attributes() 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:<br> * * <b>type</b>, <b>id</b>, <b>name</b>, <b>value</b>, <b>class</b> * * @return void */ function __construct($id, $default = '', $attributes = '') { // call the constructor of the parent class parent::__construct(); // set the private attributes of this control // these attributes are private for this control and are for internal use only // and will not be rendered by the _render_attributes() method $this->private_attributes = array('locked', 'disable_xss_filters', 'disable_zebra_datepicker', 'date', 'always_visible', 'days', 'days_abbr', 'direction', 'disabled_dates', 'enabled_dates', 'first_day_of_week', 'format', 'header_captions', 'header_navigation', 'inside_icon', 'lang_clear_date', 'months', 'months_abbr', 'offset', 'pair', 'readonly_element', 'show_clear_date', 'show_other_months', 'show_select_today', 'show_week_number', 'select_other_months', 'start_date', 'strict', 'view', 'weekend_days', 'zero_pad'); // set the javascript attributes of this control // these attributes will be used by the JavaScript date picker object $this->javascript_attributes = array('always_visible', 'days', 'days_abbr', 'direction', 'disabled_dates', 'enabled_dates', 'first_day_of_week', 'format', 'header_captions', 'header_navigation', 'inside_icon', 'lang_clear_date', 'months', 'months_abbr', 'offset', 'pair', 'readonly_element', 'show_clear_date', 'show_other_months', 'show_select_today', 'show_week_number', 'select_other_months', 'start_date', 'strict', 'view', 'weekend_days', 'zero_pad'); // set the default attributes for the text control // put them in the order you'd like them rendered $this->set_attributes(array('type' => 'text', 'name' => $id, 'id' => $id, 'value' => $default, 'class' => 'control text date', 'always_visible' => null, 'days' => null, 'days_abbr' => null, 'direction' => null, 'disable_zebra_datepicker' => false, 'disabled_dates' => null, 'enabled_dates' => null, 'first_day_of_week' => null, 'format' => 'Y-m-d', 'header_captions' => null, 'header_navigation' => null, 'inside_icon' => null, 'months' => null, 'months_abbr' => null, 'offset' => null, 'pair' => null, 'readonly_element' => null, 'show_clear_date' => null, 'show_other_months' => null, 'show_select_today' => null, 'show_week_number' => null, 'select_other_months' => null, 'start_date' => null, 'strict' => null, 'view' => null, 'weekend_days' => null, 'zero_pad' => null)); // if "class" is amongst user specified attributes if (is_array($attributes) && isset($attributes['class'])) { // we need to set the "class" attribute like this, so it doesn't overwrite previous values $this->set_attributes(array('class' => $attributes['class']), false); // make sure we don't set it again below unset($attributes['class']); } // sets user specified attributes for the control $this->set_attributes($attributes); }