public function createAction($slug, Request $request) { $em = $this->getDoctrine()->getManager(); $admission = $em->getRepository('LmcAdmissionBundle:Admission')->findOneBy(array('slug' => $slug)); $application = new Application(); $application->setAdmission($admission); $form = $this->createForm(new ApplicationFormType($em), $application, array('action' => $this->generateUrl('lmc_admission_create_application', array('slug' => $slug)))); $form->add('submit', 'submit', array('label' => 'application.form.submit')); $form->handleRequest($request); //validator :: validation.yml $validator = $this->get('validator'); $errors = $validator->validate($application); //if have valid if (count($errors) > 0) { return $this->render('LmcAdmissionBundle:Frontend:createApplication.html.twig', array('form' => $form->createView(), 'admission' => $admission)); } //End valid //if isValid return true. if ($form->isValid()) { $app_prefix = $admission->getAppPrefix(); $app_nextnum = $admission->getAppNextnum(); $app_nextnum_length = strlen($app_nextnum); $applicationKey = $app_prefix . $app_nextnum; $application->setApplicationKey($applicationKey); //make new next num $app_nextnum++; $new_app_nextnum = str_pad($app_nextnum, $app_nextnum_length, '0', STR_PAD_LEFT); $admission->setAppNextnum($new_app_nextnum); $em->persist($admission); $em->persist($application); $em->flush(); // return to thankyou // $thankyou = $admission->getThankyou(); $thankyou = $admission->getPdfContent(); $thankyou = str_replace('[APP_NUM]', $application->getApplicationKey(), $thankyou); $thankyou = str_replace('[PAGE_ONLY]', '', $thankyou); $thankyou = str_replace('[PAGE_ONLY_END]', '', $thankyou); $thankyou = str_replace('[PDF]', $this->generateUrl('lmc_admission_pdf_application', array('uniqid' => $application->getUniqid())), $thankyou); return $this->render('LmcAdmissionBundle:Frontend:thankyou.html.twig', array('thankyou' => $thankyou)); } //return twig return $this->render('LmcAdmissionBundle:Frontend:createApplication.html.twig', array('form' => $form->createView(), 'admission' => $admission)); }