2017-12-07 1 views
0

유효성 검사가 반응이없고 제출을 차단합니다. 누군가가 무엇이 누락되었거나 내가 뭘 잘못하고 있다고 말할 수 있습니까? 분명히 isValid 메서드가 호출 될 때 유효성 검사기는 유효성 검사를 차단합니다. 엔터티에서이 변수의 유효성은 다음과 같습니다. /** * @var 문자열 * @Assert \ NotBlank() */ private $ pGaWeeks;실체에서의 symfony 유효성 확인 : misssing 무엇입니까?

제출은 pGaWeeks 변수에 주어진 것을 차단하고 비워 두었을 때도 차단됩니다. 오류 메시지가 나타나지 않습니다. "@Assert \ NotBlank()"가 코드에서 제외되면 제출이 잘됩니다.

validation:  { enabled: true, enable_annotations: true } 

과 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 %} 

편집 :

나는 또한 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(), 
     )); 


    } 

그리고 config.yaml에이 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 %} 

그리고 createNewForm에 대한 코드 :

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(); 

} 
+1

당신이 DataLiveBundle'의 코드를 보여 주 시겠어요 코드 . 만약 당신이'dump ($ appendForm-> getData()); 'pGaWeeks '가 비어 있습니까? 오류를 렌더링하지 않았기 때문에 "pGaWeeks가 비어 있어서는 안됩니다."라고 표시됩니다. – baris1892

+0

'storeDataAPatient'는 무엇을합니까? –

+0

"pGaWeeks"는 항상 비어 있습니다. –

답변

-1

여기

/** 
    * 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; 
    } 

그리고는 메도의 stroeDataAPatient입니다 나는 너에게 말할 수있다, 너는 너의 상태에 넣을 수있다. n 및 유효한 경우 더 나은 성능을 위해 제출 createNewForm`method`의도 form.html.twig`과 : DataAPatient :

$form = $this->createForm(yourPathType, yourObject); 
     $form->handleRequest($request); 
     if ($form->isSubmitted() && $form->isValid()) { 
      $this->getDoctrine()->getManager()->flush(); 
     } 

짧은

+0

완전히 확신 할 수는 없지만'storeDataAPatient()'가 플러시됩니다. 당신의 대답은 추측입니다. 원래 코드로 변경 한 내용을 설명하지 않고 변수의 이름을 바꾸지도 않았습니다 ('$ form' ->'$ appendForm') –

+0

업데이트 된 질문을 참조하십시오. 당신의 대답은 질문에 대답하지 않습니다. –

관련 문제