2

how I can get value from input select in ZF3?

$education = $form->get('education');
$education->setValueOptions([
     '1' =>'option 1',
     '2' => 'option 2',
]);

returns integer value 1,2, not 'option 1' or 'option 2'

Even if I remove index and leave code like below

$education->setValueOptions([
     'option 1',
     'option 2',
]);

it doesn't work and returns the same as above.

But if I modify code like this

$education->setValueOptions([
     'option 1' => 'anything'
     'option 2' => 'anything'
]);

it returns correct values as 'option 1' or 'option 2'.

Is is correct, or I'm dooing something wrong?

2
  • did my answer help you? Commented Dec 22, 2016 at 18:57
  • 1
    yep I just selected your's answer ;) Commented Dec 22, 2016 at 19:30

1 Answer 1

1

You're thinking it wrong. For example:

$education->setValueOptions([
     'array_key' => 'array_value'
]);

In PHP the value of this array would be array_value while array_key would be the key. The logic in zend is the opposite when it is translated to the front-end. In the front end the array_key would be the <option> value while the array_value would be the <option> label.

The above code would be translated to the following in the front-end

<option value="array_key">array_value</option>
Sign up to request clarification or add additional context in comments.

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.