为什么要使用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()?

查看:173
本文介绍了为什么要使用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提交。我还将设置一个处理这些Ajax请求的特定URL,最终将调用 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.

em>将损失是内置的跨站点请求伪造保护。只要你滚动自己的版本,你应该可以。

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天全站免登陆