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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:52:52+00:00 2026-06-05T10:52:52+00:00

i have a problem with my Form in symfony. first the code: $test =

  • 0

i have a problem with my Form in symfony.

first the code:

$test = array();
    foreach($docGrp as $dc){
        $test[] = $dc->getGruppenName();
    }
    $form = $this->createFormbuilder($document)
        ->add('gruppe', 'choice', array(
        'choices'   =>array(
            'Gruppen'   =>  $test,
        ),
        'multiple'  =>  true,
        'expanded'  => true,
    ))
        ->getForm();

I want that the array is displayed as checkboxes and the values of it should be the values in the array. However, i get an Exception which says

“An exception has been thrown during the rendering of a template (“Warning: strtr() expects parameter 1 to be string, array given”

So if i change the choices to “Gruppen => “test” it works. But it defeats the purpose, i need to get those values out of the array.

If someone knows what i mean, help would be cool 🙂

so far
Adi

  • 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-05T10:52:54+00:00Added an answer on June 5, 2026 at 10:52 am

    The problem is the way you’re passing the choices through in the form. Because $test is an array you’re actually passing a 2d array through as the choices option, e.g. array(‘Gruppen’ => array(….)), which is not allowed.

    I’ve seen 2d arrays work when using a multiple select widget in Symfony. Where the widget indents the choices as the dimensions grow. But it doesn’t work with checkboxes.
    What you want to do is pass an array like:

    $countries = array(
        'au' => 'Australia',
        'at' => 'Austria',
        'az' => 'Azerbaijan',
        ...
    );
    

    Where the array keys are the values.

    $form = $this->createFormbuilder($document)
        ->add('country_code', 'choice', array(
            'choices'   => $countries
            'multiple'  =>  true,
            'expanded'  => true,
        )
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code, but it doesn't work: $builder->add('name','text',array( 'label' => 'Due Date', ));
I have a problem with my form,i have this error every time i want
I have problem with ajax and php.I have next code $(form).submit(function() { var poruka
i have problem at php $_POST code. this is the my codes? what i
I have a problem to upload an image using Symfony. I have a form
I have a problem with simple form for, I get this error url(http://localhost:3000/konkurrencer/new): Showing
I have problem in writing the code in windows form application my problem is
I have problem in sorting an array in ascending form and i don't know
I have an entity type form field in my Symfony2 project. $builder = $this->createFormBuilder();
I have problem with showing results from visits table depending on search form !

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.