【发布时间】:2013-11-18 13:34:40
【问题描述】:
我正在尝试更改 InputFilter::isValid() 方法中所需的消息。但我不知道如何为一个字段更改此特定消息。这是我的代码:
class EventFormInputFilter extends InputFilter
{
protected $dbAdapter;
protected $isEdit = false;
public function __construct(Adapter $dbAdapter, $isEdit = false)
{
$factory = $this->getFactory();
$this->dbAdapter = $dbAdapter;
$this->isEdit = $isEdit;
$this->add($factory->createInput(
[
'name' => 'market_id',
'required' => false,
'allow_empty' => false,
'filters' => [
['name' => 'Null'],
],
'validators' => [
[
'name' => '\AssetBase\Validator\Db\RecordExists',
'options' => [
'field' => 'id',
'table' => 'markets',
'adapter' => $dbAdapter,
],
],
],
]
));
$this->add($factory->createInput(
[
'name' => 'country_id',
'required' => false,
'allow_empty' => false,
'filters' => [
['name' => 'Null'],
],
'validators' => [
[
'name' => '\AssetBase\Validator\Db\RecordExists',
'options' => [
'field' => 'id',
'table' => 'countries',
'adapter' => $dbAdapter,
],
],
]
]
));
}
public function isValid()
{
$marketId = $this->getValue('market_id');
$countryId = $this->getValue('country_id');
if (empty($marketId) && empty($countryId)) {
$this->get('market_id')->setRequired(true);
// how to change required error message here?
$this->get('country_id')->setRequired(true);
// how to change required error message here?
}
return parent::isValid();
}
}
有什么想法吗?谢谢
【问题讨论】:
标签: forms validation input zend-framework2