flexy:nameuses="variable" – Use a variable in the name for a flexy form element


Usage ( flexy:nameuses="variable" name="sometag[%s]" )


If you have a form with multiple input boxes (eg. group members), which are dynamically generated, then this attribute can be used to generate flexy elements based on sprintf'ing the variable value into the name attribute value.


Template with flexy:ignore


    <title>Example of name Uses</title>
    <form name="formtest">
      <span flexy:foreach="data,key,row">
        {key}: <input name="data%s" flexy:nameuses="key" type="hidden" size="10"><br>

Backend Code Snippet

->data = array();
$elem = array();
$elem['formtest'] = &new HTML_Template_Flexy_Element();
$elem['formtest']->attributes['method'] = 'post';
$elem['formtest']->attributes['action'] = 'test';  

$i 0$i 10$i++) {
$this->data[$i] = $i;
$elem["data$i"] = new HTML_Template_Flexy_Element();
$elem["data$i"]->attributes['type'] = 'text';
$elem["data$i"]->attributes['size'] = $i;



Compiled template

    <title>Example of name Uses</title>
    <?php echo $this->elements['formtest']->toHtmlnoClose();?>
if ($this->options['strict'] || (is_array($t->data)  || is_object($t->data)))
$t->data as $key => $row) {?>
      <?php echo htmlspecialchars($key);?><?php if (!isset($this->elements[sprintf('data%s',$key)])) $this->elements[sprintf('data%s',$key)]= $this->elements['data%s'];
$this->elements[sprintf('data%s',$key)] = $this->mergeElement($this->elements['data%s'],$this->elements[sprintf('data%s',$key)]);
$this->elements[sprintf('data%s',$key)]->attributes['name'] = sprintf('data%s',$key);
<?php }?>

Resulting Output

    <title>test for PEAR bug#4683</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <form name="formtest" method="post" action="test">      
      0: <input name="data0" type="text" size="0"><br>
      1: <input name="data1" type="text" size="1"><br>
      2: <input name="data2" type="text" size="2"><br>
      3: <input name="data3" type="text" size="3"><br>
      4: <input name="data4" type="text" size="4"><br>
      5: <input name="data5" type="text" size="5"><br>
      6: <input name="data6" type="text" size="6"><br>
      7: <input name="data7" type="text" size="7"><br>
      8: <input name="data8" type="text" size="8"><br>
      9: <input name="data9" type="text" size="9"><br>
Prevent Automatic form value replacement (Previous) Provides a simple way to pass data from PHP to Javascript (Next)
Last updated: Sat, 16 Feb 2019 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

There are no user contributed notes for this page.