這是一個正確的操作。我發現answers一個couple並做到這一點的最好的地方就是覆蓋bind
功能,重新定義取決於值從表單驗證的選項(以禁用所需選項或刪除驗證):
public function bind(array $taintedValues = null, array $taintedFiles = null)
{
if($taintedValues["method"] == 'phone')
{
// disabled required
$this->validatorSchema["email"]->setOption('required', false);
}
else
{
// remove the validator
$this->validatorSchema['other_field'] = new sfValidatorPass();
// and disabled required
$this->validatorSchema["phone"]->setOption('required', false);
}
return parent::bind($taintedValues, $taintedFiles);
}
來源
2012-05-20 13:19:10
j0k
其中Symfony的版本? – j0k
Symfony v1.4.17 – Daniele
你已經檢查過[這個答案](http://stackoverflow.com/questions/6441982/validate-a-field-depending-on-another-field-value-in-symfony)? – j0k