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: