[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
Example:
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();