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 8272001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:59:41+00:00 2026-06-08T06:59:41+00:00

In my form, I want to set the selected (default) value for a select

  • 0

In my form, I want to set the selected (default) value for a select element. However, using setDefaults is not working for me.

Here is my code:

$gender = new Zend_Form_Element_Select('sltGender');
$gender->setMultiOptions(array(
    -1 => 'Gender',
    0 => 'Female',
    1 => 'Male'
))
->addValidator(new Zend_Validate_Int(), false)
->addValidator(new Zend_Validate_GreaterThan(-1), false);

$this->setDefaults(array(
    'sltGender' => 0
));

$this->addElement($gender);

My controller is simply assigning the form to a view variable which just displays the form.

It works by using $gender->setValue(0), but it would be easier to set them all at once with an array of default values. Am I misunderstanding something here?

Also, where is the Zend Framework documentation for classes and methods? I am looking for something similar to the Java documentation. The best I could find is this one, but I don’t like it – especially because every time I try to search, it crashes.

  • 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-08T06:59:43+00:00Added an answer on June 8, 2026 at 6:59 am

    Have you tried:

    $this->addElement($gender);
    
    $this->setDefaults(array(
        'sltGender' => 0
    ));
    

    Also, take a look at http://framework.zend.com/issues/browse/ZF-12021 .

    As you can see, the above issue is similar to the issue you’re describing. It seems Zend is very particular about the order you create objects and assign settings.

    I’m afraid you’re going to have to do things in the order Zend wants you to do them (which doesn’t seem well documented, but is only discovered thru trial and error), or hack their library to make it do what you want it to do.

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

Sidebar

Related Questions

How to set option selected when using jqtransform on select element. I'm using jqtransform
I have a simple select element that I want to set the value for
I want to set Selected value of a Dropdownlist in a Sharepoint List form
I create a combobox in a class and want to set the selected value
I have a form set up and working nearly perfectly. I am using the
I am trying to set the selected value in a dropdownlist using jquery, I
Hi I want to set opacity for a form in page load. I try
I have a Photo model and I want to set up a form so
I have a form whose action is set to itself. I want it this
I have a HTML form; I want to be able to set it so

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.