【问题标题】:How can i change the html pattern error message in cakephp 3 at input field如何在输入字段中更改 cakephp 3 中的 html 模式错误消息
【发布时间】:2016-09-30 17:13:38
【问题描述】:

输入字段: 如何自定义在 html 5 的输入字段中使用的模式中的错误消息。

当前消息显示“请输入与模式匹配的值”此消息在自定义“仅允许数字”后显示

<?= $this->Form->input('mobile', 
['pattern'=>"^(?!0)[0-9]{10}$",
'label' => false, 'id' => '',
 'class' => 'form-control reg_mobile_input',
'required' => true,'id'=>'',
'placeholder'=>'without initail zero',]); 
?>

【问题讨论】:

标签: html forms validation cakephp cakephp-3.0


【解决方案1】:

您可以通过将大多数属性传递给表单助手来设置它们,因此以下应该可以工作:

<?= $this->Form->input('mobile', [
    'class' => 'form-control reg_mobile_input',
    'label' => false,
    'oninvalid' => 'setCustomValidity(\'Without trailing zero\')',
    'pattern' => "^(?!0)[0-9]{10}$",
    'placeholder'=>'without initail zero'
    'required' => true,
]); ?>

有关自定义 HTML 错误消息的更多信息,请参阅 MDN docs on setCustomValidity

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-06
    • 1970-01-01
    • 2011-07-18
    • 2015-07-01
    • 2014-11-07
    • 2013-07-27
    相关资源
    最近更新 更多