0

need a tutorial about how to create custom HTML markup (like form decorators on Zend 1). I want to generate something like:

<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>
1
  • You will simply have to implement your own view helpers to handle this kind of markup. It's as simple as that :) Commented Feb 28, 2013 at 8:48

1 Answer 1

1

Assuming the form elements are named username and password, here's an example that would give the desired output

<?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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.