Symfony Form Design

I have an Event object where People objects can be present. After the event, the owner of the event sits down and should be presented with this form.

  user a user b user c user d user e user f user g user a _ user b _ user c _ user d _ user e _ user f _ user g _ 

All spaces are check boxes, whether the user likes another user. Underscores are turned off by flags, because the user cannot love himself. Should I use select_list? I want to process the input as follows:

 foreach(guests as guest)//horizontal { foreach(guests as other)//vertical { if(guest != other && guest.likes(other) && other.likes(guest)) { //do something } } } 

How can I use formbuilder to achieve something like this?

+7
symfony doctrine2 symfony-forms
source share
1 answer

Does this type of mold fit your needs?

 $userIDsArray = $userIDsArray = array('1' => 'name1','2' => 'name2','3' => 'name3','4' => 'name4'); $form = $this->createFormBuilder($initialData); foreach($userIDsArray as $userId) $form->add($userId, 'choice', array( 'choices' => $userIDsArray, 'multiple' => true, 'expanded' => true ) ); $form = $form->getForm(); 

For this array of users, checking for user 1 of the remaining three users and for user 3 only the fourth, this result will be issued.

 array (size=4) 'name1' => array (size=3) 0 => int 2 1 => int 3 2 => int 4 'name2' => array (size=0) empty 'name3' => array (size=1) 0 => int 4 'name4' => array (size=0) empty 

When visualizing the form, you can iterate over each element in the form, and then for each element that you can iterate over each choice and turn off the ones you want:

 {% for formWidget in classForm %} {{ form_label(formWidget) }} {% for child in formWidget %} {{ form_widget(child) }}</td> {% endfor %} {% endfor %} 

Of course, you can use different arrays for the strings in the form and for the selection, implementing the desired structure.

+1
source share

All Articles