I’ve just (as in today) started working on some ZF stuff.
I have a Form that needs to have some text in a div appear at the top of the form, but I have no idea how to include it.
The structure of the form is:
class MyForm extends \app\forms\FormType {
public function init() {
// gets all the form elements of the parent
parent::init();
// A few additional form elements for MyForm created here
}
}
Any help would be apprecaited!
In your controller where you instantiate the form object just set it with the view object like this:
Then put the div in the action-name.phtml script:
Contents:
Additionally, you could pass the view object by reference to your form class. Just overload the construct function like so:
Then in your controller when you instantiate your form object do this:
Let’s go back to your form class once again and modify the init() method:
Using this way, you won’t have to put any conditional if statements checking anything in the controller. You’re already checking if
$this->divTextis not empty in the view, so by passing the view object to your form class you can ensure that that text will only be set when the form is being used.