0

我的表单验证有问题:当我们这样写电子邮件时 -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

4

1 回答 1

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;
于 2015-09-02T23:35:43.303 回答