I have two entities Student and Classes and I want to create a form shows the student details and a dropdown / chocelist of classes and assign one class to the student. Also the classes should come from the DB table so the controller is like this.
public function studentAddClassAction( $id, Request $request )
{
// get the student from the student table
$em = $this->getDoctrine()->getManager();
$student= $em->getRepository('PIE10Bundle:Student')->find($id);
// new class object and create the form
$class = new Classes;
$form = $this->createForm(ClassesType::class, $class);
$form->handleRequest($request);
if( $form->isSubmitted() && $form->isValid() )
{
// form operation - update student row with the classID
}
return $this->render(
'PIE10Bundle:student:layout_student_addclass.html.twig',
array(
'student'=> $student,
'title' => 'Add Class',
'tables' => 1,
'form' => $form->createView()
)
);
}
and my ClassesType is like below
class ClassesType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('classes',
ClassesType::class,
array(
'class' => 'PIE10Bundle:Classes',
'property' => 'className',
'expanded' => false,
'multiple' => false
));
$builder->add('Add Class',
SubmitType::class,
array('attr' => array('class' => 'btn btn-primary',
'style' => 'margin:15px 0;')) );
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'PIE10Bundle\Entity\Classes',
));
}
}
and when I try to access this form I am getting the following 500 Internal Server Error - UndefinedOptionsException error
The options "class", "expanded", "multiple", "property" do not exist. Defined options are: "action", "allow_extra_fields", "attr", "auto_initialize", "block_name", "by_reference", "compound", "constraints", "csrf_field_name", "csrf_message", "csrf_protection", "csrf_token_id", "csrf_token_manager", "data", "data_class", "description", "disabled", "empty_data", "error_bubbling", "error_mapping", "extra_fields_message", "inherit_data", "invalid_message", "invalid_message_parameters", "label", "label_attr", "label_format", "mapped", "method", "post_max_size_message", "property_path", "required", "translation_domain", "trim", "validation_groups".
So I need to know what went wrong and how to fix this. Please let me know if any other information needed. Thanks