Teraz chciałbym to przerobić aby upload następował bez przeładowania...
Mam problem gdyż formularz nie przechodzi walidacji, nie wiem jak mam wysłać cały formularz do kontrolera i go "zbindować"...?
JS
Kod
$("#uploadFileAjax").submit(function(){
var url=$("#uploadFileAjax").attr("action");
$.post(url,{
watch:$("#picturetype_watch").val(),
file:$("#picturetype_file").val(),
_token:$("#picturetype__token").val()
},function(data){
},"json");
return false;
});
var url=$("#uploadFileAjax").attr("action");
$.post(url,{
watch:$("#picturetype_watch").val(),
file:$("#picturetype_file").val(),
_token:$("#picturetype__token").val()
},function(data){
},"json");
return false;
});
Kod
public function ajaxUploadAction()
{
$form = $this->createForm(new \Acme\MyBundle\Form\PictureType());
if($this->getRequest()->getMethod() == 'POST')
{
$form->bindRequest($this->getRequest());
if($form->isValid())
{
$em = $this->getDoctrine()->getEntityManager();
$data = $form->getData();
$em->persist($data);
$em->flush();
} else {
print_r($form->getErrorBubbling());
print_r($form->getErrors());
}
}
$return=json_encode('ok');
return new Response($return,200,array('Content-Type'=>'application/json'));
}
{
$form = $this->createForm(new \Acme\MyBundle\Form\PictureType());
if($this->getRequest()->getMethod() == 'POST')
{
$form->bindRequest($this->getRequest());
if($form->isValid())
{
$em = $this->getDoctrine()->getEntityManager();
$data = $form->getData();
$em->persist($data);
$em->flush();
} else {
print_r($form->getErrorBubbling());
print_r($form->getErrors());
}
}
$return=json_encode('ok');
return new Response($return,200,array('Content-Type'=>'application/json'));
}
Inne pliki Entity, Formularz jest takie jak w tutorialu...
i mam błąd:
'The CSRF token is invalid. Please try to resubmit the form'
Co źle robię ?