Validation is not reacting and blocks the submitting. Could someone tell me what is missing or what am I doing wrong? Apparently, when the method isValid is called, the validator blocks the validation. In entity, this variable is validated as follows: /** * @var string * @Assert\NotBlank() */ private $pGaWeeks;
The submission is blocked what ever is given to the variable pGaWeeks and also when left empty. There does not appear any error message. The submission works fine when "@Assert\NotBlank()" is taken away from the code.
I have also a DataHomeController.php
public function newAction(Request $request){
if(!$this->hasFuAccess() || !$this->isAdmin()){
throw new AccessDeniedException("You do not have permission to access");
}
$newrecord =array();
$dataA = new DataAPatient();
array_push($newrecord,$dataA);
$appendForm = $this->createNewForm($dataA);
$appendForm->handleRequest($request);
if($appendForm->isSubmitted()){//Save
if($appendForm->isValid()){
$tmp_pKpPatientid = $this->storeDataAPatient($dataA);
$records = $this->getStepByStepSearch($dataA);
return $this->render('GeneralCommonBundle:DataHome:show.html.twig', array(
'records'=> $records,
'isNew' => false,
'newrecord' => $newrecord
));
}
// }
}
return $this->render('DataLiveBundle:DataAPatient:new.html.twig', array(
'form' => $appendForm->createView(),
));
}
And in config.yaml:
validation: { enabled: true, enable_annotations: true }
And an html.twig:
{% extends '::base.html.twig' %}
{% block body %}
{{ form_start(form, {attr: {novalidate: 'novalidate'}}) }}
{% form_theme form 'bootstrap_3_horizontal_layout.html.twig' %}
<h1 style="margin-top:60px"><img src="{{ asset('public/images/icons/icon_data_gross.gif') }}"> Create a New Patient Dataset</h1>
<div role="tabpanel" class="tab-pane active" id="PatientInfo">
<div class="panel panel-default">
<div class="panel-body">
{% include 'DataLiveBundle:DataAPatient:form.html.twig' with {
'form':form, 'isNew': true } only %}
</div>
</div>
</div>
{{ form_row(form._token) }}
{{ form_end(form) }}
{% endblock %}
EDIT:
DataLiveBundle:DataAPatient:form.html.twig:
{% block body %}
<div class="row" style='margin-bottom: 5px'>
<div style='white-space: nowrap'>
<div class='col-xs-5'>
<div class='col-xs-5'>{{ form_label(form.pSnnid, 'SNN-ID (if known)', {'label_attr':{'style':'margin-top:3px'}})}}</div>
<div class='col-xs-2'>{{ form_widget(form.pSnnid, {'attr':{'style':'width:105px'}})}}</div>
</div>
<div class='col-xs-5'>
<div class='col-xs-5'>{{ form_label(form.pPlaceOfBirth, 'Place of birth', {'label_attr':{'style':'margin-top:3px' }})}}</div>
<div class='col-xs-2'>{{ form_widget(form.pPlaceOfBirth , {'attr': {'style':'width:200px' }})}}</div>
</div>
</div>
</div>
<div class="row" style='margin-bottom: 5px'>
<div style='white-space: nowrap'>
<div class='col-xs-5'>
<div class='col-xs-5'>{{ form_label(form.pDateOfBirth, 'Date of birth', {'label_attr':{'style':'margin-top:3px'}})}}</div>
<div class='col-xs-2'> {{ form_widget(form.pDateOfBirth, {'id': 'P_Date_of_birth','attr':{'style':'width:100px', }})}}</div>
</div>
<div class='col-xs-5'>
<div class='col-xs-5'>{{ form_label(form.pPatientNo, 'Patient ID / Nr. NEO', {'label_attr':{'style':'margin-top:5px'}})}}</div>
<div class='col-xs-2'>{{ form_widget(form.pPatientNo, {'attr':{'style':'width:105px' }})}}</div>
</div>
</div>
</div>
<div class="row" style='margin-bottom: 5px'>
<div style='white-space: nowrap'>
<div class='col-xs-5'>
<div class='col-xs-5'>{{ form_label(form.pGaWeeks, 'Gestational age', {'label_attr':{'style':'margin-top:3px'}})}}</div>
<div class='col-xs-2'> <div class="input-group">{{ form_widget(form.pGaWeeks, {'id': 'P_GA_weeks', 'attr':{'style':'width:45px'}})}}<div class="input-group-addon">w</div></div>
<div class="input-group">{{ form_widget(form.pGaDays, {'id': 'P_GA_days','attr':{'style':'width:45px' }})}}<div class="input-group-addon">d</div></div></div>
</div>
<div class='col-xs-5'>
<div class='col-xs-5'>{{ form_label(form.pBirthWeight, 'Birth weight', {'label_attr':{'style':'margin-top:3px'}})}}</div>
<div class='col-xs-2'><div class="input-group">{{ form_widget(form.pBirthWeight, {'attr':{'style':'width:60px'}})}}<div class="input-group-addon">g</div></div></div>
</div>
</div>
</div>
<div class="row" style='margin-bottom: 5px'>
<div style='white-space:nowrap'>
<div class='col-xs-5'>
<div class='col-xs-5'>{{ form_label(form.pSex, 'Sex/Gender', {'label_attr':{'style':'margin-top:3px'}})}}</div>
<div class='col-xs-2' style='margin-top: 5px'>{{ form_widget(form.pSex, {'attr':{'style':'text-indent:10px'}})}}</div>
</div>
<div class='col-xs-5'>
<div class='col-xs-5'>{{ form_label(form.pNumberOfInfants, 'No. of infants in birth', {'label_attr':{'style':'margin-top:5px'}})}}</div>
<div class='col-xs-2'>{{ form_widget(form.pNumberOfInfants, {'attr':{'style':'width:35px'}})}}</div>
</div>
</div>
</div>
<div class="row" style='margin-bottom: 5px'>
<div style='white-space: nowrap'>
<div class='col-xs-5'>
{#<div class='col-xs-5'>{{ form_label(form.pEpoStudy, 'Child in EPO study')}}</div>#}
{# <div class='col-xs-2'>{{ form_widget(form.pEpoStudy, {'attr':{'style':'text-indent:10px'}})}}</div>#}
</div>
<div class='col-xs-5'>
<div class='col-xs-5'>{{ form_label(form.pRank, 'Rank (if >1)', {'label_attr':{'style':'margin-top:5px'}})}}</div>
<div class='col-xs-2'>{{ form_widget(form.pRank, {'attr':{'style':'width:35px'}})}}</div>
<div style='padding-right: 80px; margin-top: 8px'> (A/B/C/D..)</div>
</div>
</div>
<div style= 'padding-left:40px ; margin-top:50px;'> (<font color=red>*</font> = input necessary)</div>
{% if isNew == true %}
<div class='col-xs-2'>{{ form_widget(form.submit_new, {'attr':{'style':'width:160px ; color:red; margin-left:900px'}})}}</div>
{% else %}
<div style="padding-left:1000px"> <a class='btn btn-default btnNext'><font color=red>Continue »</font></a></div>
{% endif %}
</div>
{% endblock %}
And the code for createNewForm:
/**
* Creates a form to create a new DataAPatient entity.
*
* @param DataAPatient $entity The entity
*
* @return \Symfony\Component\Form\Form
*
*/
private function createNewForm(DataAPatient $entity)
{
$form = $this->createForm($this->get('data_livebundle.form.dataapatienttype'), $entity, array(
'action' => $this->generateUrl('dataapatient_new'),
'method' => 'POST',
));
$form->add('submit', 'submit', array('label' => 'Create'));
return $form;
}
And here is the methode stroeDataAPatient:
private function storeDataAPatient($dataA){
if (!$dataA) {
throw $this->createNotFoundException('Unable to find DataEFu2 entity.');
}
$em = $this->getDoctrine()->getManager();
$session = $this->getRequest()->getSession();
$em->persist($dataA);
$em->flush();
$tmp_pKpPatientid= $dataA->getpKpPatientid();
}
storeDataAPatient:
private function storeDataAPatient($dataA){
if (!$dataA) {
throw $this->createNotFoundException('Unable to find DataEFu2 entity.');
}
$em = $this->getDoctrine()->getManager();
$session = $this->getRequest()->getSession();
$em->persist($dataA);
$em->flush();
$tmp_pKpPatientid= $dataA->getpKpPatientid();
}
DataLiveBundle:DataAPatient:form.html.twig
and also ofcreateNewForm
method. What is displayed if youdump($appendForm->getData());
? Is yourpGaWeeks
empty? The error ("pGaWeeks should not be blank") is not shown because you did not render it I would guess... – baris1892storeDataAPatient
do? – Stephan Vierkant