I’d like to allow a candidate that previously register to come back to his registration and add (and only) missing documents.
Here is my view
<form action="{{ path('candidat_update', { 'id': entity.id }) }}" method="post" {{ form_enctype(edit_form) }}>
{% if ((entity.file2)==0)%}
{{ form_row(edit_form.file2, { 'label': 'file2' }) }}
{% endif %}
<p>
<button class="btn-small" type="submit">update</button>
</p>
</form>
When clicking on button update, nothing is happening (no redirection to show view, no upload)
My controller’s updateAction :
public function updateAction(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('EtienneInscriptionBundle:Candidat')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Candidat entity.');
}
$deleteForm = $this->createDeleteForm($id);
$editForm = $this->createForm(new CandidatType(), $entity);
$editForm->bind($request);
if ($editForm->isValid()) {
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('candidat_show', array('id' => $entity->getId())));
#return $this->redirect($this->generateUrl('candidat_edit', array('id' => $id)));
}
return array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
}
Where CandidateType contains the builder that generates initially every fields on create action (CRUD based controller)
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name') ....etc...
Any ideas on what’s wrong ?
Thanx
It’s not a good idea to filter your form fields in your template.
Better is to use options when building your form. Here’s an example on how you can do it,
1) Set conditions to add fields to your form,
2) Define your options,
3) Build your Form,