2014-09-23 3 views
0

연락처 폼의 필드를 검증하려고하는데, 폼 자체가 잘 작동하고 데이터를 게시하고 있지만 유효성 검사를 마친 상태입니다. this 설명서에 따르면 설정 검증은 꽤나 간단하지만 어떤 이유로 그것이 나를 위해 작동하지 않습니다.Symfony 2.5의 폼 유효성 확인

번들을 만들었을 때 validation.yml 번들이 번들의 구성 폴더에 없으므로 수동으로 생성 했으므로 내 validation.yml이 그 것처럼 보입니다. 이것은 이것은

namespace ClickTeck\ContactBundle\Controller; 

use Symfony\Bundle\FrameworkBundle\Controller\Controller; 
use ClickTeck\ContactBundle\Entity\Enquiry; 
use ClickTeck\ContactBundle\Form\EnquiryType; 
use Symfony\Component\HttpFoundation\Request; 
class DefaultController extends Controller 
{ 
    public function indexAction(Request $request) 
    { 
     $enquiry = new Enquiry(); 
     $form = $this->createForm(new EnquiryType(), $enquiry); 

      $form->handleRequest($request); 

      if ($form->isValid()) { 
       return $this->redirect($this->generateUrl('contact_form')); 
      } 

     return $this->render('ContactBundle:Default:contact.html.twig', array(
       'form' => $form->createView() 
      )); 
    } 
} 

처럼 DefaultController는 모습입니다

ClickTeck\ContactBundle\Entity\Enquiry: 
    properties: 
     name: 
      - NotBlank: ~ 
      - Length: 
       min: 2 
       max: 50 
       minMessage: "Your first name must be at least {{ limit }} characters long" 
       maxMessage: "Your first name cannot be longer than {{ limit }} characters long" 

Enquiry.php 폴더

<?php 

namespace ClickTeck\ContactBundle\Entity; 

use Doctrine\ORM\Mapping as ORM; 

/** 
* Enquiry 
*/ 
class Enquiry 
{ 
    /** 
    * @var integer 
    */ 
    private $id; 

    /** 
    * @var string 
    */ 

    private $name; 

    /** 
    * @var string 
    */ 
    private $email; 

    /** 
    * @var string 
    */ 
    private $subject; 

    /** 
    * @var string 
    */ 
    private $body; 


    /** 
    * Get id 
    * 
    * @return integer 
    */ 
    public function getId() 
    { 
     return $this->id; 
    } 

    /** 
    * Set name 
    * 
    * @param string $name 
    * @return Enquiry 
    */ 
    public function setName($name) 
    { 
     $this->name = $name; 

     return $this; 
    } 

    /** 
    * Get name 
    * 
    * @return string 
    */ 
    public function getName() 
    { 
     return $this->name; 
    } 

    /** 
    * Set email 
    * 
    * @param string $email 
    * @return Enquiry 
    */ 
    public function setEmail($email) 
    { 
     $this->email = $email; 

     return $this; 
    } 

    /** 
    * Get email 
    * 
    * @return string 
    */ 
    public function getEmail() 
    { 
     return $this->email; 
    } 

    /** 
    * Set subject 
    * 
    * @param string $subject 
    * @return Enquiry 
    */ 
    public function setSubject($subject) 
    { 
     $this->subject = $subject; 

     return $this; 
    } 

    /** 
    * Get subject 
    * 
    * @return string 
    */ 
    public function getSubject() 
    { 
     return $this->subject; 
    } 

    /** 
    * Set body 
    * 
    * @param string $body 
    * @return Enquiry 
    */ 
    public function setBody($body) 
    { 
     $this->body = $body; 

     return $this; 
    } 

    /** 
    * Get body 
    * 
    * @return string 
    */ 
    public function getBody() 
    { 
     return $this->body; 
    } 

} 

이것은 EnquiryType.php 폴더 Entity 내부

namespace ClickTeck\ContactBundle\Form; 

use Symfony\Component\Form\AbstractType; 
use Symfony\Component\Form\FormBuilderInterface; 

class EnquiryType extends AbstractType 
{ 
    public function buildForm(FormBuilderInterface $builder, array $options) 
    { 
     $builder->add('name'); 
     $builder->add('email', 'email'); 
     $builder->add('subject'); 
     $builder->add('body', 'textarea'); 
    } 

    public function getName() 
    { 
     return 'contact'; 
    } 
} 
입니다 Entity 내부 누군가가 올바른 방향으로 날 지점 수 있다면

모든 마지막으로 내 contact 템플릿

{% extends '::base.html.twig' %} 
{% block title %}Contact{% endblock %} 
{% block body %} 
    <div class="container"> 
     <div class="row"> 
      <header> 
       <h1>Contact Us</h1> 
      </header> 
      {{ form_errors(form) }} 
      <form action="{{ path('contact_form') }}" method="post" {{ form_enctype(form) }} role="form" 
        class="form-horizontal"> 
       {{ form_errors(form) }} 
       <div class="form-group"> 
        <div class="col-sm-2 control-label"> 
         {{ form_label(form.name) }} 
        </div> 
        <div class="col-sm-10"> 
         {{ form_widget(form.name, { 'attr': {'class': 'form-control'} }) }} 
        </div> 
       </div> 
       <div class="form-group"> 
        <div class="col-sm-2 control-label"> 
         {{ form_label(form.email) }} 
        </div> 
        <div class="col-sm-10"> 
         {{ form_widget(form.email, { 'attr': {'class': 'form-control'} }) }} 
        </div> 
       </div> 
       <div class="form-group"> 
        <div class="col-sm-2 control-label"> 
         {{ form_label(form.subject) }} 
        </div> 
        <div class="col-sm-10"> 
         {{ form_widget(form.subject, { 'attr': {'class': 'form-control'} }) }} 
        </div> 
       </div> 
       <div class="form-group"> 
        <div class="col-sm-2 control-label"> 
         {{ form_label(form.body) }} 
        </div> 
        <div class="col-sm-10"> 
         {{ form_widget(form.body, { 'attr': {'class': 'form-control', 'rows':'10'} }) }} 
        </div> 
       </div> 
       {{ form_rest(form) }} 
       <div class="form-group"> 
        <div class="col-sm-offset-2 col-sm-10"> 
         <input type="submit" value="Send Message" class="btn btn-primary"/> 
        </div> 
       </div> 
      </form> 
     </div> 
    </div> 
{% endblock %} 

내가 어떤 오류가 발생하지 않는 빈 이름 필드와 양식을 제출

, 정말 감사합니다.

답변

0

이것은 내 문제를 해결 한 것입니다. app/config/config.yml 기본적으로 유효성 검사가 해제되어있는 것으로 보이며, 다음과 같이 변경하고 모든 유효성 검사를 수행했습니다.

framework: 
    validation:  { enabled: true, enable_annotations: false }