开发者

How do you add javascript to forms in the Zend Framework?

How do you add javascript to forms created with the Zend framework? For instance, if I wanted to validate the form, or if I wanted to ut开发者_运维百科ilize events like blur, focus and onclick?


What I tend to do is :

  • From the PHP code, generate the form, using Zend_Form and the related classes
    • This includes setting up the form itself,
    • But also server-side validations and all that
  • Once the form works fine, I add Javascript in an un-obstrusive way.
    • Which means my JS code is totally distinct from the PHP/Zend_Form code.
    • And also mean my form doesn't rely on Javascript being activated in the user's browser, as the form already works before.


If you are using jQuery, you can detect when the page is loaded $.ready, and hook a function on that event -- function that will add some dynamic bahaviors to your form.

Of course, you can do the same sort of thing with other JS libraries -- I only took jQuery as an example because of its popularity, and the fact there are some jQuery-related components in ZendX.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜