关于php:在客户端重用Zend验证器

Reusing Zend validators on client-side

我在另一个没有找到任何答案的论坛上发现了这个问题。我认为这是一个很好的问题,值得在这里提出。我在这里逐字粘贴。

Hi guys, I've got a pie in the sky
idea, and I'm just wondering if it's
even remotely possible, or if I should
give up and try something else.

I've got a bunch of Zend_Dojo_Form
forms with a bunch of custom
validators on the Zend side - they
work fine, the form errors out when
values are incorrect, it's all working
exactly as you'd expect, however, what
I'd also like is for the same
validators to work on the Dojo client
side of the form - but without having
to completely re-implement them,
validator by validator.

I understand that at its simplest
level, the Dojo isValid method doesn't
know or care about the application
behind it, and indeed for it to even
be able to get access to the errors in
the application it'd have to attempt a
submit, which isn't what it's meant to
do, but has anyone tried a system of
something like:

  • override form onSubmit to add our code
  • test Dojo isValid()
  • if the Dojo side is happy, AJAX submit the form
  • if successful, which would be returned i don't know how, then
    forward on to the appropriate page
  • if not successful, then (and this is where it gets tricky I guess) pass
    back enough data to know what field
    errored out, what the error was, and
    then call enough of the Dojo isValid
    internal guts to make the form look
    like it didn't validate?
  • Sorry to just be airing ideas like
    this, I just figured it might be
    really useful if we could come up with
    a way to sort of globally add custom
    validators to our forms that work both
    client and server side, without having
    to implement them uniquely on both
    sides.


    Meh,dojo:(

    使用Jquery:)

    看看这真棒:
    使用jQuery

    Ajaxify您的Zend_Form验证

    We’re going to take what was put
    together in the last 3 videos and now
    include some server-side validation
    that will appear asynchronously. This
    is an example of using Zend_Form as a
    validation tool via JSON.


    Zend_Form有一个processAjax()方法,可用于验证任何或所有表单元素,并返回JSON编码的结果(真或错误列表)。

    因此,它可以用于在onsubmit事件处理程序中对表单的全部或部分进行预验证;甚至是在其onchange事件处理程序中单独预先验证字段。