Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.3.13

Bug #13028 Chackboxes with flexy:nameuses in PHP4
Submitted: 2008-01-31 18:20 UTC
From: cbrunet Assigned:
Status: Open Package: HTML_Template_Flexy (version 1.3.2)
PHP Version: 4.4.4 OS:
Roadmaps: (Not assigned)    
Subscription  


 [2008-01-31 18:20 UTC] cbrunet (Charles Brunet)
Description: ------------ See sample script. It works in PHP5, but on PHP4 at my web hoster, values aren't set correctly. Compiled template are identical from PHP4 and PHP5. If I replace checkbox with radio, it also works normally. It isn't new to 1.3.2. It was the same in 1.2.5. If I remove nameuses from the template, values are set normally. Test script: --------------- <? require_once "HTML/Template/Flexy.php"; require_once "HTML/Template/Flexy/Element.php"; $flexy_options = array( 'templateDir' => ".", 'compileDir' => ".", 'forceCompile' => 0, 'debug' => 0, 'locale' => 'en', 'compiler' => 'Flexy', ); class MaListe { function MaListe() { global $flexy_options; $this->elements = array(); $this->elements["ckbox[]"] = new HTML_Template_Flexy_Element(); $this->elements["ckbox[]"]->setAttributes(array("flexy:xhtml"=>true)); $this->elements["ckbox[]"]->setValue(array(1)); $this->a = array(1=>"bonjour",2=>"allo",3=>"salut"); $tmpl = new HTML_Template_Flexy($flexy_options); $tmpl->compile("modele.html"); echo $tmpl->bufferedOutputObject($this, $this->elements); } } new MaListe; ?> modele.html: <html> <body> <form> {foreach:a,i,n} <input type="checkbox" name="ckbox[]" flexy:nameuses="i" id="c%s" value="{i}" />{n}<br/> {end:} </form> </body> </html> Expected result: ---------------- <input type="checkbox" name="ckbox[]" id="c1" value="1" checked="checked" />bonjour<br /> <input type="checkbox" name="ckbox[]" id="c2" value="2" checked="checked" />allo<br /> <input type="checkbox" name="ckbox[]" id="c3" value="3" checked="checked" />salut<br /> Actual result: -------------- <input type="checkbox" name="ckbox[]" id="c1" value="1" checked="checked" />bonjour<br /> <input type="checkbox" name="ckbox[]" id="c2" value="1" checked="checked" />allo<br /> <input type="checkbox" name="ckbox[]" id="c3" value="1" checked="checked" />salut<br />

Comments

 [2008-02-01 02:55 UTC] alan_k (Alan Knowles)
can you post what the compiled template looks like for both versions. Thanks Alan
 [2008-02-01 20:16 UTC] cbrunet (Charles Brunet)
Compiled template are identical on both PHP version (I verified with diff): <html> <body> <form> <?php if ($this->options['strict'] || (is_array($t->a) || is_object($t->a))) foreach($t->a as $i => $n) {?> <?php if (!isset($this->elements['c%s']->attributes['value'])) { $this->elements['c%s']->attributes['value'] = ''; $this->elements['c%s']->attributes['value'] .= htmlspecialchars($i); } $_attributes_used = array('value'); if (!isset($this->elements[sprintf('ckbox[]',$i)])) { $this->elements[sprintf('ckbox[]',$i)]= $this->elements['c%s']; } $this->elements[sprintf('ckbox[]',$i)] = $this->mergeElement( $this->elements['c%s'], $this->elements[sprintf('ckbox[]',$i)] ); $this->elements[sprintf('ckbox[]',$i)]->attributes['name'] = sprintf('ckbox[]',$i); $this->elements[sprintf('ckbox[]',$i)]->attributes['id'] = sprintf('c%s',$i); echo $this->elements[sprintf('ckbox[]',$i)]->toHtml(); if (isset($_attributes_used)) { foreach($_attributes_used as $_a) { unset($this->elements['c%s']->attributes[$_a]); }} ?><?php echo htmlspecialchars($n);?><br /> <?php }?> </form> </body> </html>
 [2008-12-08 03:23 UTC] heikkiu (Heikki Uusitalo)
This is what happens in the template: if (!isset($this->elements[sprintf('ckbox[]',$i)])) { $this->elements[sprintf('ckbox[]',$i)]=$this->elements['c%s']; } // 'ckbox[]' get its value from 'c1' $this->elements[sprintf('ckbox[]',$i)] = $this->mergeElement( $this->elements['c%s'], $this->elements[sprintf('ckbox[]',$i)] ); // the value set in 'ckbox[]' (2nd arg.) overwrites the value of 'c1' echo $this->elements[sprintf('ckbox[]',$i)]->toHtml(); // 'ckbox[]' is printed This is somewhat similar to my recent bug http://pear.php.net/bugs/bug.php?id=15272 I'm still trying to figure this one out. Particularly baffling is why this would be different in PHP4. Presumably has to do with mergeElement returning a reference in PHP5 (patched in 1.3.5)...