PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » HTML » HTML_QuickForm » Bug #9731

callback.php

Details

Submitted2007-01-04 09:29 UTC
Fromnechiporenko at ecommerce dot com
StatusBogus
PackageHTML_QuickForm
PHP Version5.1.2
OSWinXP
Roadmaps(Not assigned)

Comments

[2007-01-04 09:29 UTC] nechiporenko at ecommerce dot com

Description:
------------
PATH: HTML_QuickForm/QuickForm/RuleCallback.php
line: 66

return call_user_func(array($callback[1], $callback[0]), $value, $options);

First argument passed is array whereas call_user_func requires a valid callback function. That produced a runtime error when I tried to execute a test script given at
http://www.gvngroup.be/doc/LiveUser/authentication_example.php

Test script:
---------------
<?php

function page_top()
{
echo '<html><head>';
echo '<link rel="stylesheet" type="text/css" href="test.css" media="screen" />';
echo '</head><body>';
}

function page_bottom()
{
echo '</body></html>';
}

function show_login()
{
ini_set("include_path", '../../libs/PEAR/' . PATH_SEPARATOR . ini_get("include_path"));
require_once ("HTML/QuickForm.php");
echo '<p>Please log in to access this page</p>';
$form =& new HTML_Quickform('logon', 'post');

$renderer =& $form->defaultRenderer();
$renderer->setElementTemplate('<tr><td align="left" valign="top" width="150">
<p><span class="label">{label}</span><!-- BEGIN required -->
<span class="mandatory"> (*)</span><!-- END required --></p></td>
<td valign="top" align="left"><!-- BEGIN error --><span class="error_msg">{error}</span>
<br /><!-- END error -->{element}</td></tr>');

$note='<span class="mandatory">(*)</span><span style="font-size:80%;"> Mandatory</span>';
$form->setRequiredNote($note);

$form->addElement('text', 'handle', 'Userid', array('class'=>'text'));
$form->addRule('handle', 'Userid is mandatory', 'required');

$form->addElement('password', 'passwd', 'Password', array('class'=>'text'));
$form->addRule('passwd','Password is mandatory', 'required');
$form->registerRule('check_pswd', 'callback', 'is_pswd_ok', $form);
$form->addRule('passwd', 'Logon failed', 'check_pswd');

$form->addElement('advcheckbox', 'rememberMe', '', ' Remember me',
array('class'=>'text'), array(false,true));

$form->addElement('submit', 'btnSubmit', 'Login');

if (!$form->validate())
{
$form->display();
}
}

function is_pswd_ok(&$passwd)
{
$LU->login($LU->getProperty('handle'),$LU->getProperty('passwd'));
if ($LU->isLoggedIn())
{
return true;
}
else
{
return false;
}

}
?>

Expected result:
----------------
to pass a valid callback, not an array at
PATH: HTML_QuickForm/QuickForm/RuleCallback.php
ine: 66

Actual result:
--------------
Warning: call_user_func(Array) [function.call-user-func]: First argument is expected to be a valid callback in C:\WebServers\home\test1.ru\www\includes\HTML\QuickForm\Rule\Callback.php on line 66

Btw, argument order is also odd as at first an object is given. I could think that it is done knowingly with intention to execute ObjectName->methodname ($callback[1], $callback[0]). Thus here bug will be in test script itself (as function is_pswd_ok is not a part of HTML_QuickForm object).

[2007-01-04 10:10 UTC] mansion at php dot net

The example you based your work upon is wrong.
It should read
$form->registerRule('check_pswd', 'callback', 'is_pswd_ok');
instead of
$form->registerRule('check_pswd', 'callback', 'is_pswd_ok',
$form);
since 'is_pswd_ok' lives in global scope.

http://pear.php.net/manual/en/package.html.html-quickform.html-quickform.registerrule.php