Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8483925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:14:28+00:00 2026-06-10T20:14:28+00:00

To Create a text input box I used folling code in zend framework2 use

  • 0

To Create a text input box I used folling code in zend framework2

use Zend\Form\Form;

class Loginform extends Form
{
    public function __construct()
    {
           $this->add(array(            
            'name' => 'usernames',
            'attributes' =>  array(
                'id' => 'usernames',                
                'type' => 'text',
            ),
            'options' => array(
                'label' => 'User Name',
            ),
        ));       
    }
}

and I can populate the values in controller action using

$form = new Loginform();
$form->get('usernames')->setAttribute('value', 'user 1');

Any idea how can I do the same for Selection/drop down box in zf2?

Ref: zend framework 2 documentation

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T20:14:30+00:00Added an answer on June 10, 2026 at 8:14 pm

    Check the API (the docs are terrible, so check the code).

    Use the Zend\Form\Element\Select class and set the options attribute like so:

    $element->setAttribute('options', array(
        'key' => 'val',
        ...
    ));
    

    Output the element using the FormRow or FormSelect view helper.

    This site is also a good source for examples and information: http://zf2.readthedocs.org/en/latest/modules/zend.form.quick-start.html

    Example:

    $this->add(array(     
        'type' => 'Zend\Form\Element\Select',       
        'name' => 'usernames',
        'attributes' =>  array(
            'id' => 'usernames',                
            'options' => array(
                'test' => 'Hi, Im a test!',
                'Foo' => 'Bar',
            ),
        ),
        'options' => array(
            'label' => 'User Name',
        ),
    ));    
    

    You can also assign the options in the controller if you need to, as shown above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create an input form that will take the input text and
(from the mailing list) How do I create some sort of text input box
I'd like to create a text input with a clear button in a confined
i create two input text fields , one for title and another for permanent
I'm trying to create a service in which the user will input some text
I am trying to create an SEO-friendly link from the input in a text
i create a form for order a item in flex. i use <mx:TextInput />
I create a subscribe block in my page, include text box and button submit.
I want to create a simple gsp page which will have an input box
I'm trying to create a text widget that includes an entry form on top

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.