gpt4 book ai didi

forms - Symfony2:如何将自定义错误消息转换为表单类型?

转载 作者:行者123 更新时间:2023-12-03 12:29:14 24 4
gpt4 key购买 nike

我需要翻译我的表单类型中的错误消息。这是我的表单类型代码:

class ReferFriendType extends AbstractType {

public function buildForm(FormBuilder $builder, array $options)
{
$defaultSubject = "This is a default referral subject.";
$defaultMessage = "This is a default referral message.";

$builder->add('email1', 'email',array(
'required' => true,
'label' => 'Email 1* :',
'attr' => array('class' => 'large_text'),
));
$builder->add('email2', 'email',array(
'label' => 'Email 2 :',
'required' => false,
'attr' => array('class' => 'large_text'),
));
$builder->add('email3', 'email',array(
'label' => 'Email 3 :',
'required' => false,
'attr' => array('class' => 'large_text'),
));
$builder->add('email4', 'email',array(
'label' => 'Email 4 :',
'required' => false,
'attr' => array('class' => 'large_text'),
));
$builder->add('email5', 'email',array(
'label' => 'Email 5 :',
'required' => false,
'attr' => array('class' => 'large_text'),
));
$builder->add('subject', 'text', array(
'data' => $defaultSubject,
'required' => true,
'label' => 'Subject* :',
'attr' => array('class' => 'large_text'),
));
$builder->add('message', 'textarea', array(
'data' => $defaultMessage,
'required' => true,
'label' => 'Message* :',
'attr' => array('rows' => '5', 'cols' => '40'),
));

}

public function getDefaultOptions(array $options)
{
$collectionConstraint = new Collection( array(
'fields' => array(
'email1' => array(
new Email(),
new NotBlank(array(
'message' => 'You must enter atleast one email address for a valid submission',
)),
),
'subject' => new NotBlank(),
'message' => new NotBlank(),
),
'allowExtraFields' => true,
'allowMissingFields' => true,
));

return array(
'validation_constraint' => $collectionConstraint,
'csrf_protection' => false,
);
}

public function getName()
{
return 'referFriend';
}

}

我想将getDefaultOptions()方法中的“您必须输入至少一个电子邮件地址以进行有效提交”翻译成法语。我已经在messages.fr.yml中添加了翻译。但是它没有得到翻译。任何想法如何做到这一点?

最佳答案

验证翻译将转到validators.LANG.yml文件,而不是messages.LANG.yml文件。

关于forms - Symfony2:如何将自定义错误消息转换为表单类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10395535/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com