Reputation: 95
I use the Zend Framework 1.12, and I am trying to create a form with Zend_Form like this:
<form action="">
<div class="bb-validator-form">
<div class="form-question">
Question 1?
</div>
<div class="form-row" >
<input type="radio" name="form-val-q" id="yes" class="radio radio-yes"/>
<label for="yes"><?php echo $this->tra->_('Yes'); ?></label>
</div>
<div class="form-row">
<input type="radio" name="form-val-q" id="no" class="radio radio-no"/>
<label for="no"><?php echo $this->tra->_('No'); ?></label>
</div>
<input type="submit" class="btn btn-primary btn-block" value="<?php echo $this->tra->_('Validate'); ?>"/>
</div>
My code in Zend Form is:
class Form_BB_Validator extends Zend_Form {
public function init()
{
$this->setMethod(Zend_Form::METHOD_POST)
->setAttribs(array('id' =>'bb-Form'))
->addDecorator('FormElements')
->addDecorator('HtmlTag', array('tag' => 'div','class'=>'bb-validator-form'))
->addDecorator('Form');
$this->addElement('text','question-1',array(
'label' => 'test',
'decorators'=>array(array('Callback',array('callback'=>
create_function('','return "<h4> Question 1 ?</h4>";'))))
));
$this->addElement('radio','checkValidation', array(
'class' => 'radio',
'escape' => false,
'required' => true,
'multioptions' => array('yes'=>'Yes', 'no'=>'No'),
'decorators' => array(
array('FormElements', array('HtmlTag', array('tag'=>'div','class'=>'bb-validator-form'))),
array('ViewHelper', array('Label', array('tag'=>'div','class'=>'bb-validator-form'))),
)
));
$this->addElement(new Zend_Form_Element_Submit('submit', array(
'label' => 'Valider',
'class' => 'btn btn-primary btn-block',
'decorators' => array(array('ViewHelper', array('Label', array('tag'=>'div','class'=>'bb-validator-form'))),
))));
}
}
The final output is:
<form id="bb-Form" enctype="application/x-www-form-urlencoded" action="" method="post">
<div class="bb-validator-form">
<h4>Question 1 ?</h4>
<dt id="checkValidation-label"> </dt>
<label for="checkValidation-yes">
<input type="radio" name="checkValidation" id="checkValidation-yes" value="yes" class="radio">Oui</label>
<br>
<label for="checkValidation-no">
<input type="radio" name="checkValidation" id="checkValidation-no" value="no" class="radio">Non</label>
<input type="submit" name="submit" id="submit" value="Valider" class="btn btn-primary btn-block">
</div>
</form>
This is not correct. How do I create the form like first piece of code?
Upvotes: 1
Views: 672
Reputation: 691
You could use custom viewScript. Like this:
$this->setDecorators(
array(
array(
'ViewScript',
array(
'viewScript' => $viewsPath . '/form-bb-validator.phtml'
)
)
)
);
In form-bb-validator.phtml you can design your html output like this:
<form>...
<div>
<?php echo $this->element->question-1; ?>
</div>
...
</form>
Upvotes: 1