在Symfony2中,只有当复选框的值为1(True)时,如何验证输入字段不是空白 - 否则允许空白?
更确切地说,我有一个带有复选框的表单和一个带有文本类型的输入字段.在Symfony中的实体中,应该检查当复选框的值为True(1)/选中时,输入的值不能为空.我在实体中使用注释.
任何建议将不胜感激.
更新/解决方案 - 基于GeLo的评论:
<?php
// src/ZeroSpace/Invoicing/Entity/Customer.php
namespace ZeroSpace\InvoicingBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity
* @ORM\Table(name="customers")
* @UniqueEntity("billing_id")
* @UniqueEntity("billing_name")
*/
class Customer {
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="integer", length=6, unique=true)
* @Assert\Length(min="6", max="6")
*/
protected $billing_id;
/**
* @ORM\Column(type="string", length=100, unique=true)
*/
protected $billing_name;
/**
* @ORM\Column(type="string", nullable=true, length=100)
*/
protected $billing_consignee;
/**
* @ORM\Column(type="string", length=100)
*/
protected $billing_street; …Run Code Online (Sandbox Code Playgroud)