Source for file hierselect-ajax.php
Documentation is available at hierselect-ajax.php
* Usage example for HTML_QuickForm2 package: AJAX-backed hierselect element.
* NB: This usage example requires HTML_AJAX package to work.
require_once 'HTML/QuickForm2.php';
require_once 'HTML/QuickForm2/Renderer.php';
require_once 'HTML/AJAX/Helper.php';
require_once './support/hierselect-loader.php';
'syncHS' => array (2 , 16 ),
'asyncHS' => array (2 , 16 )
$fsSync = $form->addElement ('fieldset')->setLabel ('Sync call');
$fsSync->addElement ('hierselect', 'syncHS', array ('style' => 'width: 250px;'))
->setLabel ('Choose package:')
->loadOptions (array ($loader->getOptions (), array ()),
array ($loader, 'getOptions'), 'loadOptionsSync')
->setSeparator ('<br />');
$fsAsync = $form->addElement ('fieldset')->setLabel ('Async call');
$fsAsync->addElement ('hierselect', 'asyncHS', array ('style' => 'width: 250px;'))
->setLabel ('Choose package again:')
->loadOptions (array ($loader->getOptions (), array ()),
array ($loader, 'getOptions'), 'loadOptionsAsync')
->setSeparator ('<br />');
$form->addElement ('submit', 'testSubmit', array ('value' => 'Send'));
$form->render ($renderer);
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<title>HTML_QuickForm2: AJAX-backed hierselect element</title>
/* Set up custom font and form width */
font-family: Arial,sans-serif;
/* Use default styles included with the package */
if ('@data_dir@' != '@' . 'data_dir@') {
$filename = '@data_dir@/HTML_QuickForm2/quickform.css';
// output script tags for AJAX server
$ajaxHelper = new HTML_AJAX_Helper ();
$ajaxHelper->serverUrl = 'js/hierselect-server.php';
$ajaxHelper->stubs [] = 'OptionLoader';
echo $ajaxHelper->setupAJAX ();
<script type="text/javascript">
function loadOptionsSync(keys)
return (new OptionLoader).getOptionsAjax(keys);
function loadOptionsAsync(keys, selectId)
// trying to load options for an empty value (or waiting for an async
if ('' == keys[keys.length - 1]) {
return qf.elements.hierselect.missingOptions;
getOptionsAjax: qf.elements.hierselect.getAsyncCallback(selectId, keys)
(new OptionLoader(callback)).getOptionsAjax(keys);
// actual options will be added later, for now just return empty options
// (this will also prevent useless AJAX requests)
return qf.elements.hierselect.missingOptions;
// Inline QuickForm's javascript libraries
echo $renderer->getJavascriptBuilder ()->getLibraries (true , true );
if ('POST' == $_SERVER['REQUEST_METHOD']) {
Documentation generated on Wed, 10 Apr 2019 08:56:09 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|