[dev] Horde_View_Helper_Form->label

Sebastian Birnbach birnbacs at gmail.com
Fri Jan 30 10:04:18 UTC 2015


I wrote a little test page to get to grips with Horde_Forms. I have files
moreview.php and viewtest/moretemplate.php, please see below.

Problem is, I can't get the label() method to output 'for' tags as
described in
https://dev.horde.org/api/master/lib/View/class-Horde_View_Helper_Form.html#_label
:

$this->label('post', 'title');// => <label for="post_title">Title</label>


I do, however, get the the 'for' tag when I specify it as an array of
options.

What am I doing wrong?

Another thing: Horde_View_Helper_Form->radioButton() takes $objectName and
$method as the first two parameters. I assume $objectName stands for the
group of radiobuttons and $method for the form the group is in. Shouldn't
that be usable for setting the id of the radioButton?

Thanks

  Sebastian


***
moreview.php:
***

<?php

require_once __DIR__ . '/lib/Application.php';
Horde_Registry::appInit('abakus');

// create a new view
$view = new Horde_View(array('templatePath' => 'viewtest'));

// add a horde_form object
$view->hordeformrenderer = new Horde_Form_Renderer;

// and render template file "moretemplate.php"
echo $view->render('moretemplate.php');


***
moretemplate.php:
***

<!-- a form -->

<?php
    // define the form action
    echo $this->hordeformrenderer->open('index.php');

    // add radio buttons
    $this->addHelper('Horde_View_Helper_Form');

    echo '<br>', $this->radioButton('set1', 'form1', 'opt_1', array('id' =>
'clickthis'));
    echo $this->label('', '', 'Click here', array('for' => 'clickthis',
'form' => 'form1'));
    print "\n";

    echo '<br>', $this->radioButton('set1', 'form1', 'opt_2',
array('checked' => '1', 'id' => 'nothis'));
    echo $this->label('GET', 'nothis', 'No, click here', array('for' =>
'nothis', 'form' => 'form1'));
    print "\n";

    echo '<br>', $this->radioButton('set1', 'form1', 'opt_3', array('id' =>
'bestclick'));
    echo $this->label('GET', 'title', 'This is probably the best button to
click', array('for' => 'bestclick', 'form' => 'form1'));
    print "\n";

    // add submit and reset buttons
    echo $this->hordeformrenderer->submit('outyougo', 'reset');

?>

***
resulting HTML code:
***

  <!-- a form --><form action="index.php
<view-source:http://192.168.0.182/abakus/index.php>"
method=""><br><input id="clickthis" name="set1[form1]" type="radio"
value="opt_1" /><label for="clickthis" form="form1">Click
here</label><br><input checked id="nothis" name="set1[form1]"
type="radio" value="opt_2" /><label>No, click here</label><br><input
id="bestclick" name="set1[form1]" type="radio" value="opt_3" /><label
for="bestclick" form="form1">This is probably the best button to
click</label><div class="horde-form-buttons">    <input
class="horde-default" name="submitbutton" type="submit"
value="outyougo" />    <input name="resetbutton" type="reset"
value="reset" /></div>***


More information about the dev mailing list