0

I have this form input:

echo $this->Form->input('category_id',array('label'=>'Catégorie','type'=>"select",'options'=>$categories,'empty'=>false));

Now, $category is filled with those informations:

Array
(
[0] => Array
    (
        [categories] => Array
            (
                [id] => 1
                [nom] => Autre
            )

    )

[1] => Array
    (
        [categories] => Array
            (
                [id] => 2
                [nom] => Véhicule
            )

    )

[2] => Array
    (
        [categories] => Array
            (
                [id] => 3
                [nom] => Audio/video
            )

    )

)

I would like that the Select input shows only the "nom" field (name), but that it sends the ID when the form is submitted. Is that possible in CakePHP? I've been crawling through Google and CakePHP's doc and forums for a while without success :-/

Thank you in advance guys and have a nice day!

2 Answers 2

1

Cakephp uses a single dimension array for select options. You change your your to single dimension with id as your key and nom as text of option tag and then pass it to options key:

$categories = Set::combine($categories,'{n}.categories.id','{n}.categories.nom');
Sign up to request clarification or add additional context in comments.

Comments

0

You should respect Cakephp conventions. Remplace "nom" by "name" in your database and cakephp will do it automatically if your associations have been well done.

1 Comment

I would do this, but sadly the conventions already established in my company won't let me do this. Thanks for the answer though.

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.