Package: Controls

Class: Zebra_Form_Password

source file: /includes/Password.php

Class Overview


Class for password controls.



  • (c) 2006 - 2016 Stefan Gabos


Inherited methods

Class: Zebra_Form_Control

Call this method to instruct the script to force all letters typed by the user, to either uppercase or lowercase, in real-time.
Disables the SPAM filter for the control.
Disables XSS filtering of the control's submitted value.
Returns the values of requested attributes.
Locks the control's value. A locked control will preserve its default value after the form is submitted even if the user altered it.
Resets the control's submitted value (empties text fields, unchecks radio buttons/checkboxes, etc).
Sets one or more of the control's attributes.
Sets a single or an array of validation rules for the control.
Converts the array with control's attributes to valid HTML markup interpreted by the toHTML() method

Class: XSS_Clean

Sanitizes submitted data so that Cross Site Scripting Hacks can be prevented.

Class methods

constructor __construct()

void __construct ( string $id , [ string $default = ''] , [ array $attributes = ''] )

Adds an <input type="password"> control to the form.

Do not instantiate this class directly! Use the add() method instead!

  1. // create a new form
  2. $form new Zebra_Form('my_form');
  4. // add a password control to the form
  5. $obj $form->add('password''my_password');
  7. // don't forget to always call this method before rendering the form
  8. if ($form->validate()) {
  9.     // put code here
  10. }
  12. // output the form using an automatically generated template
  13. $form->render();
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.

  1. // in a template file, in order to print the generated HTML
  2. // for a control named "my_password", one would use:
  3. echo $my_password;
string $default (Optional) Default value of the password field.
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 "disabled" attribute
  2. $obj $form->add(
  3.     'password',
  4.     'my_password',
  5.     '',
  6.     array(
  7.         'disabled' => 'disabled'
  8.     )
  9. );

There's a special data-prefix attribute that you can use to add uneditable prefixes to input fields (text, images, or plain HTML), as seen in the image below. It works by injecting an absolutely positioned element into the DOM, right after the parent element, and then positioning it on the left side of the parent element and adjusting the width and the left padding of the parent element, so it looks like the prefix is part of the parent element.

If the prefix is plain text or HTML code, it will be contained in a <div> tag having the class Zebra_Form_Input_Prefix; if the prefix is a path to an image, it will be an <img> tag having the class Zebra_Form_Input_Prefix.

For anything other than plain text, you must use CSS to set the width and height of the prefix, or it will not be correctly positioned because when the image is not cached by the browser the code taking care of centering the image will be executed before the image is loaded by the browser and it will not know the image's width and height!

  1. // add simple text
  2. // style the text through the Zebra_Form_Input_Prefix class
  3. $form->add('password''my_password'''array('data-prefix' => 'Hash:'));
  5. // add images
  6. // set the image's width and height through the img.Zebra_Form_Input_Prefix class
  7. // in your CSS or the image will not be correctly positioned!
  8. $form->add('password''my_password'''array('data-prefix' => 'img:path/to/image'));
  10. // add html - useful when using sprites
  11. // again, make sure that you set somewhere the width and height of the prefix!
  12. $form->add('password''my_password'''array('data-prefix' => '<div class="sprite image1"></div>'));
  13. $form->add('password''my_password'''array('data-prefix' => '<div class="sprite image2"></div>'));

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


method toHTML()

string toHTML ( )

Generates the control's HTML code.

This method is automatically called by the render() method!

return: The control's HTML code