我的表单验证有问题:当我们写这样的电子邮件时 - foo@bar
- 错误没有显示,但表单发送也失败了。我该如何解决?
[[!FormIt?
&hooks=`spam,email,redirect,FormItAutoResponder`
&emailTpl=`emailTplContact`
&emailTo=`my@email.com`
&validate=`email:email:required,
name:required,
agree:required`
&redirectTo=`2532`
&fiarTpl=`emailAutoRespond`
&fiarSubject=`Success`
&fiarFromName=`English School`
&fiarFrom=`my@email.com`
&fiarToField=`email`
&fiarReplyTo=`email`
]]
<form method="post" action="[[~[[*id]]]]">
<label for="name">Name</label><input required="required" type="name" id="name" name="name" placeholder="Your name" value="[[!+fx.name]]">
[[!+fx.error.name]]
<label for="email">E-mail </label><input required="required" type="email" id="email" name="email" placeholder="Your email" value="[[!+fx.email]]">
[[!+fx.error.email]]
</div>
<div>
<label for="phone">Phone number</label> <input type="text" placeholder="Phone number" id="phone" name="phone" value="[[+fx.phone]]" size=15/>
<input type="checkbox" name="agree" id="agree"><label for="agree" [[!+fx.agree:FormItIsChecked=`true`]]>I agree</label>
[[!+fx.error.agree]]</div>
<button id="join">JOIN</button>
</form>
我在这里找到http://bugs.modx.com/issues/4022这个错误的描述,似乎这个问题必须解决 - 但是如何解决?我的FormIT版本 - 2.0.3
答案 0 :(得分:0)
简单的解决方案 - 创建您自己的客户验证工具 - https://rtfm.modx.com/extras/revo/formit/formit.validators
例如:
<?php
if (!filter_var($value, FILTER_VALIDATE_EMAIL)) {
$validator->addError($key,'Wrong email!');
}
return true;