在您自己的自定义表单上显示CCK Filefield或Imagefield Upload Widget
花了大量的搜索找到这一个的解决方案。随着节点画廊 3.x的分公司,我们需要一种方法来快速的图像添加到现有的画廊。我们可以显示整个节点的形式,但是有很多事情在表单上,我们可以使用默认值99%的时间。我们只需要填写三个字段:Title,Caption和imagefield本身。要使用相同的图像字段窗口小部件在您自己的字段上的节点添加字段处理所有的辛苦工作,首先在hook_menu中创建一个处理程序,如下所示:
然后,在node_gallery.pages.inc中,创建执行工作的表单函数:
这很简单,直到28-30行。这三行设置表单数组,然后将content_field_form()的结果附加到我们现有的表单。仍然,很容易,但我不能找到任何文档如何做到这一点。为了防万一你好奇,这里是提交处理程序的形式。
没有什么新的。最终的结果是一个漂亮的外观,简洁的形式,使您可以快速上传图片到图库。甜!
Display a CCK Filefield or Imagefield Upload Widget on Your Own Custom Form
Took a fair amount of googling around to find the solution to this one. With the Node Gallery 3.x branch, we needed a way to quickly add an image to an existing gallery. We could have displayed the whole node form, but there’s a lot of things on that form that we can just use the defaults for 99% of the time. We need just three fields filled in: Title, Caption, and the imagefield itself. To use the same imagefield widget that handles all the hard work for you on the node add field on your own field, first create a handler in hook_menu such as this:
Then, in node_gallery.pages.inc, you create the form function that does the work:
This is pretty straightforward, up until lines 28 - 30. Those three lines setup the form array and then append the results from content_field_form() to our existing form. Still, very easy, but I wasn’t able to find any documentation on how to do this. Just in case you’re curious, here’s the submit handler for that form.
Nothing new there. The end result is a nice looking, concise form that allows you to quickly upload an image to a gallery. Sweet!
gosh I love you mate, saved me loads of time. – saadlulu Feb 1 '12 at 9:16