// create an instance of the Form class $form = new Zend\Form\Form(); // add form elements and set attributes $form->add(array( 'name' => 'username', 'type' => 'Text', 'options' => array( 'label' => 'Username', ), 'attributes' => array( 'class' => 'form-control', // set CSS class for the form element 'placeholder' => 'Enter username', // set placeholder text for the form element ) ));
// create an instance of the Form class $form = new Zend\Form\Form(); // add form elements and set attributes $form->add(array( 'name' => 'email', 'type' => 'Email', 'options' => array( 'label' => 'Email Address', ), 'attributes' => array( 'required' => 'true', // set HTML5 required attribute for the form element ) ));In this example, we create a form element for an email input field and set the required attribute using setAttribute method. The package library for PHP Zend\Form is "zendframework/zend-form" and it can be installed using composer.