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 #1984

hierselect producing extra characters

Details

Submitted2004-07-26 17:51 UTC
Frompear dot 20 dot rytsarsky at spamgourmet dot com
Assignedavb
StatusClosed
PackageHTML_QuickForm
PHP Version4.3.3
OSlinux
Roadmaps(Not assigned)

Comments

[2004-07-26 17:51 UTC] pear dot 20 dot rytsarsky at spamgourmet dot com

Description:
------------
When displaying a form with a hierselect, the characters '//]]>' appear right before the first (main) element. The resulting html has

//]]>
</script>
//]]>
</script>

right there. I'm guessing that that should just be there once.

Reproduce code:
---------------
$form = new QuickForm('', 'get');
$sel =& $form->addElement('hierselect', 'category', 'Category: ');
$form->addElement('submit', 'submit', 'Search');
$sel->setMainOptions($main);
$sel->setSecOptions($sec);
echo $form->toHtml();

Expected result:
----------------
Category: [MainSelect] [SecSelect]

Actual result:
--------------
Category: //]]>[MainSelect] [SecSelect]

[2004-07-27 14:47 UTC] pear dot 20 dot rytsarsky at spamgourmet dot com

Okay... I was able to produce a test case that demonstrates this bug.

Here's the code: (mainly from http://www.thelinuxconsultancy.co.uk/quickform.html)

----------
<?php
require_once "HTML/QuickForm.php";
$form = new HTML_QuickForm('frmTest', 'get');

$main = array();
$secondary = array();

$main[0] = "England";
$main[1] = "Scotland";
$main[2] = "USA";

$secondary[0][0] = "London";
$secondary[0][1] = "Manchester";
$secondary[0][2] = "Liverpool";
$secondary[1][3] = "Edinburgh";
$secondary[1][4] = "Glasgow";
$secondary[2][5] = "Fort Worth";
$secondary[2][6] = "Boston";
$secondary[2][7] = "Los Angles";

$sel =& $form->addElement('hierselect', 'location', 'Location:');
$sel->setMainOptions($main);
$sel->setSecOptions($secondary);
$form->addElement('submit', 'btnSubmit', 'Submit');

if ($form->validate()) {
// Form is validated, then processes the data
$form->freeze();
$form->process('process_data', false);
}
else {
$renderer =& $form->defaultRenderer();
$form->accept($renderer);
$form->display();
}

function process_data ($values) {
echo "<pre>";
var_dump($values);
echo "</pre>";
}
?>

----------

Just by adding the two lines:
$renderer =& $form->defaultRenderer();
$form->accept($renderer);

You can see the behavior described in the initial report.

[2004-07-27 17:32 UTC] pear dot 20 dot rytsarsky at spamgourmet dot com

First, I'm not just getting the default renderer, then accepting it... I'm actually changing it between those steps, so they have to stay, but the changes don't have to be there to see the bug. In other words...

$renderer =& $form->defaultRenderer();
// do stuff to $renderer here, but that doesn't effect the bug
$form->accept($renderer);
$form->display();

Also, setting the renderer and calling echo $form->toHtml() as suggested still results in those extra characters.

As I understand it, setting the renderer doesn't actually render the form, it just tells the object how to render when toHtml or display is called.

[2004-07-28 03:09 UTC] pear dot 20 dot rytsarsky at spamgourmet dot com

My Bad. It's just that that method worked for all elements other than hierselect. I still say this is a bug. I wasn't trying to get tech support, I was simply trying to explain what I did to see the bug. Sorry I misread your code, your solution does seem to work, except that it now requires hidden elements to be added to the form before all the other elements, weird.