0

Am trying to add options in my Zend_Form_Element_Select element

$monthvalues = new Zend_Form_Element_Select('month_values');
$table = new Model_DbTable_Options();
$monthvalues->addMultiOptions($table->Months())

In my Model_DbTable_Options model I have

public function Months()
    {
        $array = array(
        '01' => 'Jan',
        '02' => 'Feb',
        '03' => 'Mar',
        '04' => 'Apr',
        '05' => 'May',
        '06' => 'Jun',
        '07' => 'Jul',
        '08' => 'Aug',
        '09' => 'Sep',
        '10' => 'Oct',
        '11' => 'Nov',
        '12' => 'Dec',
        );

        return $array;
    }

It aint giving me the desired outcome. Whats missing?

1
  • What is the current outcome ? Commented Apr 4, 2010 at 1:46

2 Answers 2

1

Create Array like this

$myArray = array( 'NULL' => 'Select Month',
                     '1' => 'Jan',
                     '2' => 'Feb',
                     '3' => 'Mar',
                     '4' => 'Apr',
                     '5' => 'May',
                     '6' => 'Jun',
                     '7' => 'Jul',
                     '8' => 'Aug',
                     '9' => 'Sep',
                    '10' => 'Oct',
                    '11' => 'Nov',
                    '12' => 'Dec'
                 );

Create element like this:

$selectElement = $this->CreateElement('select', 'months');
$selectElement->setLabel('Label');
$selectElement->addMultiOptions( $myArray );
Sign up to request clarification or add additional context in comments.

Comments

0

Be careful! If you add a NULL value like this to your Zend Form your $model that you will save will have the value string(4) "NULL"

//in the form

$task->addMultiOption('NULL','');

//as it appears in html

select id="fk_id_task_task" name="fk_id_task_task" option label="" value="NULL" /option

//model from form values

$values = $form->getValues(); $model->fromArray($values, true);

//dump the $model and you end up with string(4) "NULL"

$model->fk_id_task_task = string(4) "NULL"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.