0

我正在使用 FormValidation.io 来验证输入...我想使用声明性插件来验证表单,以便我可以让我的模板引擎处理 (PHP) 验证失败后显示的消息的翻译。
我可以使用require,max_length和其他常规 HTML5 属性,但我似乎无法弄清楚如何以相同的方式使用其他插件。

我查看了https://formvalidation.io/guide/validators/vat#options中的文档,并执行了以下操作:

    <form id="sampleForm" action="<?= url("test/test") ?>" method="post" enctype="multipart/form-data" autocomplete="off" novalidate>
    <div class="form-group mb-3">
        <div class="input-group">

            <input name="sample_one" type="text" class="form-control form-control-lg" 
            required
            data-fv-vat___country="AT" 
            data-fv-vat-message___message="not a valid vat id"
            data-fv-not-empty___message="<?= lg("form_msg_required") ?>"
            />
      
        </div>
            <button type="submit" class="btn btn-primary mt-2">submit</button>
    </div>
</form>

在我的脚本文件中:

document.addEventListener('DOMContentLoaded', function (e) {
  let form = document.getElementById('sampleForm');
  FormValidation.formValidation(
    form,
    {
      plugins: {
        trigger: new FormValidation.plugins.Trigger(),
        bootstrap: new FormValidation.plugins.Bootstrap(),
        submitButton: new FormValidation.plugins.SubmitButton(),
        declarative: new FormValidation.plugins.Declarative({
          html5Input: true,
      }),
        icon: new FormValidation.plugins.Icon({
          valid: 'fa fa-check',
          invalid: 'fa fa-times',
          validating: 'fa fa-refresh'
        })
      },
    })
    .on('core.form.valid', function () {
      ajaxForm(form);
    });
});

这仅验证 require 条件。

你能帮助我或指导我正确的方向吗?我很确定我只是缺少一些简单的东西。谢谢你,很抱歉代码格式不正确。

4

0 回答 0