0

カスタム HTML マークアップの作成方法に関するチュートリアルが必要です (Zend 1 のフォーム デコレータなど)。次のようなものを生成したい:

<ul>
<li>
    <label class="required"><span>*</span> Username</label>
    <input id="username" name="username" type="text">
</li>
<li>
    <label class="required"><span>*</span> Password</label>
    <input id="password" name="password" type="password">
</li>
</ul>
4

1 に答える 1

1

フォーム要素に名前が付けられていると仮定するとusernamepassword目的の出力が得られる例を次に示します。

<?php
// attributes to apply to label(s)
$labelAttr = array('class' => 'required');
// extra label content (assumes Username and Password are already present in the given elements)
$labelSpan = '<span>*</span> ';
// set the label attributes
$form->get('username')->setLabelAttributes($labelAttr);
$form->get('password')->setLabelAttributes($labelAttr);
?>

<ul>
<li>
    // use the formLabel helper, hand it the extra label content, and tell it to place the existing label after it
    <?php echo $this->formLabel($form->get('username'), $labelSpan, 'append');
    <?php echo $this->formInput($form->get('username');
</li>
<li>
    <?php echo $this->formLabel($form->get('password'), $labelSpan, 'append');
    <?php echo $this->formInput($form->get('password');
</li>
</ul>
于 2013-02-28T11:51:46.843 に答える