2

I have a form that accepts multiple arrays of id's, when then should insert it into the database. Here is the code:

This is part of the collection type

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
        ->add('records', CollectionType::class, array(
            'entry_type' => EntityType::class,
            'entry_options' => array(
                'class' => Document::class
            )
        ))
        ->add('submit', SubmitType::class);
}

This is part of the javascript that sends a AJAX POST request:

    function addDocument(runsheet, documents) {
        var params = {};
        params.runsheet_documents = {};
        params.runsheet_documents.records = documents;

        return $http.post(API_CONFIG.url + '/runsheets/' + runsheet + '/documents', params)
            .success(function(current, response) {
                return true;
            })
            .error(function(response) {
                return false;
            }
        );
    }

This is my controller for the route:

public function postDocumentsAction(Request $request, Runsheet $runsheet)
{
    $form = $this->createForm(RunsheetDocumentsType::class, $runsheet);
    $form->submit($request->request->all());

    $runsheet = $form->getData();
    $this->get('title.api.runsheet')->update($runsheet);
    $this->get('title.logger.event')->flush();
}

Whenever I try to send an AJAX POST request I get this:

Error from Symfony profiler

KNgu
  • 355
  • 4
  • 11
  • check this http://stackoverflow.com/questions/34298641/symfony2-how-to-allow-form-to-ignore-extra-fields – devilcius May 27 '16 at 07:25
  • Have you tried tried using `$form->handleRequest($request)` instead of submitting the POST parameters to the form yourself directly? – Berry Ligtermoet May 28 '16 at 18:17

0 Answers0