use Zend\Form\Form; use Zend\Form\Element; $form = new Form('login-form'); $form->add([ 'name' => 'email', 'type' => Element\Email::class, 'options' => [ 'label' => 'Email address', ], 'attributes' => [ 'required' => true, ], ]); $form->add([ 'name' => 'password', 'type' => Element\Password::class, 'options' => [ 'label' => 'Password', ], 'attributes' => [ 'required' => true, ], ]); $form->prepare(); echo $form->render();
use Zend\Form\Form; use Zend\Form\Element; $form = new Form('contact-form'); $form->add([ 'name' => 'name', 'type' => Element\Text::class, 'options' => [ 'label' => 'Your name', ], 'attributes' => [ 'required' => true, ], ]); $form->add([ 'name' => 'email', 'type' => Element\Email::class, 'options' => [ 'label' => 'Your email address', ], 'attributes' => [ 'required' => true, ], ]); $form->add([ 'name' => 'subject', 'type' => Element\Text::class, 'options' => [ 'label' => 'Subject', ], 'attributes' => [ 'required' => true, ], ]); $form->add([ 'name' => 'message', 'type' => Element\Textarea::class, 'options' => [ 'label' => 'Message', ], 'attributes' => [ 'required' => true, ], ]); $form->prepare(); echo $form->render();In both examples, the Form prepare method is called before rendering the form. This sets up the necessary form options and attributes to ensure that the rendered form is complete and functional. The package library for these examples is the Zend Form component of the Zend Framework.