[ class tree: HTML_QuickForm_Rule_Spelling ] [ index: HTML_QuickForm_Rule_Spelling ] [ all elements ]

Class: HTML_QuickForm_Rule_Spelling

Source Location: /HTML_QuickForm_Rule_Spelling-0.2.0/Spelling.php

Class Overview


HTML QuickForm Spelling Rule


  • David Sanders (shangxiao at


  • Release: 0.2.0


Inherited Variables

Inherited Methods

Class Details

[line 127]
HTML QuickForm Spelling Rule

A HTML_QuickForm rule plugin that checks the spelling of its value(s). This rule uses drivers, of which the default is HTML_QuickForm_Rule_Spelling_Pspell.

Each value is broken up into words which are then checked individually. If any words are found to be misspelt, they will be added to a list to be used on the client side by the javascript frontend. This frontend is a dialog that will cycle through each misspelt word for all the applied fields and give the user the choice to either ignore the word, add it to the dictionary on the server or change the word to one of the listed suggestions.

This rule may be applied to multiple fields via the use of an array, or applied singular fields one at a time. The spellchecker will go cycle through each misspelt word of each specified field for that form (and only that form).

The following parameters are required to be passed in through the options field:

  • form A reference to the HTML_QuickForm object.
  • element_name The name of the element the rule applies to. If this rule was applied to an array of elements, this must be an array of names in the same order.
The following options are set statically via HTML_QuickForm_Rule_Spelling::setOption():
  • allow_ignore Whether to allow words to be ignored.
  • allow_add Whether to allow words to be added to the dictionary.
  • word_delimiter Regular expression to use as delimiter.
  • spellchecker Spellchecking driver. Either create your own or use HTML_QuickForm_Rule_Spelling_Pspell.
Known Bugs/Limitations

  • IE and Safari do not support multiple selections
  • IE <7 does not support fixed positioning
  • IE7 only supports fixed positioning when in strict mode, however not even in quirks mode does it support the expression workaround for fixed positioning. The expression workaround


require_once 'HTML/QuickForm.php'; require_once 'HTML/QuickForm/Rule/Spelling.php';

$pspell_config = pspell_config_create('en', 'british'); pspell_config_personal($pspell_config, './personal.pws'); require_once 'HTML/QuickForm/Rule/Spelling/Pspell.php'; HTML_QuickForm_Rule_Spelling::setOption('spellchecker', new HTML_QuickForm_Rule_Spelling_Pspell($pspell_config));

// Uncomment the following line to disable ignoring words //HTML_QuickForm_Rule_Spelling::setOption('allow_ignore', false);

// Uncomment the following line to disable adding words //HTML_QuickForm_Rule_Spelling::setOption('allow_add', false);

$form = new HTML_QuickForm; $form->addElement('textarea', 'text_1', 'Text 1'); $form->addElement('textarea', 'text_2', 'Text 2'); $form->addElement('submit', 'submit', 'Submit');

$form->addRule('text_1', 'Please correct the spelling mistakes', 'spelling', array('form' => $form, 'element_name' => 'text_1')); $form->addRule('text_2', 'Please correct the spelling mistakes', 'spelling', array('form' => $form, 'element_name' => 'text_2'));

// or alternatively apply the rule in one go //$form->addRule(array('text_1','text_2'), 'Please correct the spelling mistakes', 'spelling', // array('form' => $form, // 'element_name' => array('text_1','text_2')));

$form->validate(); $form->display();

[ Top ]

Method Detail

HTML_QuickForm_Rule_Spelling (Constructor)   [line 165]

HTML_QuickForm_Rule_Spelling HTML_QuickForm_Rule_Spelling( )

Constructor - Retrieve options

[ Top ]

getOption   [line 670]

string getOption( option $option)

Option Getter
  • Return: or null
  • Access: public


option   $option   —  option to get

[ Top ]

setOption   [line 652]

void setOption( option $option, [value $value = null])

Option Setter
  • Access: public


option   $option   —  option to set
value   $value   —  value to set option to

[ Top ]

validate   [line 180]

bool validate( value $values, options $options)

Validate hook. Checks the spelling.
  • Return: False if a word is not in the dictionary, true otherwise
  • Access: public


value   $values   —  The value(s) passed from HTML_QuickForm
options   $options   —  Any extra information passed to the rule

[ Top ]

Documentation generated on Mon, 11 Mar 2019 15:11:00 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.