为什么要使用 Drupal 的 Form API &Ajax 框架,而不是仅仅通过调用 node_save() 来实现我自己的解决方案? [英] Why should I use Drupal's Form API & Ajax framework for this rather than just implementing my own solution with calling node_save()?

查看:8
本文介绍了为什么要使用 Drupal 的 Form API &Ajax 框架,而不是仅仅通过调用 node_save() 来实现我自己的解决方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望用户能够通过 AJAX 提交节点和评论.我还想对节点和评论表单进行一些相当广泛的自定义.

I want users to be able to submit nodes and comments via AJAX. I also want to do some fairly extensive customization of the node and comment forms.

我已经花时间查看 Drupal 7 的 Form API 和 Ajax 框架的文档和代码示例,但我发现它非常复杂.因此,我只想在 HTML 中创建自己的表单并使用自己的 JavaScript 代码通过 Ajax 提交它.我还将设置一个特定的 URL 来处理这些 Ajax 请求,最终将在适当的时候调用 node_save()comment_save().

I've spent time looking through documentation and code examples for Drupal 7's Form API and Ajax framework, but I find it very complex. Therefore, I simply want to create my own form in HTML and use my own JavaScript code to submit it via Ajax. I'll also set up a specific URL for processing these Ajax requests, which will ultimately call node_save() or comment_save() when appropriate.

与通过 Form API 和 Ajax 框架相比,这样做有什么缺点?我不是为了对社区做出贡献而创建模块.一切只为我自己的网站.

What are the downsides to doing it this way as opposed to going through the Form API and Ajax framework? I'm not creating modules for contribution to the community. Everything is just for my own site.

推荐答案

我猜通常的论点是关于可移植性,但如果你不打算将这些模块移植到另一个 Drupal 站点,那么我猜那会失败.

The usual argument would be about portability I guess, but if you're not going to be porting these modules to another Drupal site then I guess that falls down.

同样的道理也适用于为其他模块提供基于某些全局/继承设置来更改表单的机会,但同样,如果您真的不想要/需要此功能,那么它就不能真正用作参数反对.

The same can be said for offering other modules the chance to alter your form based on some global/inherited setting, but again if you really don't want/need this functionality then it can't really be used as an argument against.

失去的一件事是内置的跨站点请求伪造保护.不过,只要您推出自己的版本,就应该没问题.

The one thing you will lose out on is the built in Cross-Site Request Forgery protection. As long as you're rolling your own version of that, though, you should be ok.

如果您打算经常使用 Drupal,我建议您习惯 FAPI...不过一段时间后,实际上使用 FAPI 比编写自定义 HTML 容易得多.

If you plan to use Drupal a lot I'd recommend getting used to the FAPI though...after a while it actually becomes a lot easier to use the FAPI than write out custom HTML.

这篇关于为什么要使用 Drupal 的 Form API &Ajax 框架,而不是仅仅通过调用 node_save() 来实现我自己的解决方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆