简体   繁体   English

在Drupal块中上传表单

[英]Upload form inside Drupal block

I wish to make an upload form inside a Drupal block (with PHP-code enabled) and I wish the validation / treatment to be on the same block. 我希望在Drupal块 (启用PHP代码) 制作一个上传表单,并且希望验证/处理在同一块上。

All I have found are either PHP specific code (creating a form and redirect to an 'upload.php' page) or Drupal module code (upload.inc with functions to create, submit and validate the form)... 我发现的只是PHP特定代码(创建表单并重定向到“ upload.php”页面)或Drupal模块代码(upload.inc,具有创建,提交和验证表单的功能)...

What should I do? 我该怎么办?

There is the advanced block module that can help you place form inside a block. 有一个高级块模块 ,可以帮助您将表单放置在块内。 Could also try the form block module if that works for this situation depending on what the upload is for. 如果适合这种情况,也可以尝试使用表单块模块 ,具体取决于上传的内容。

Custom Module: This can also be easily done via custom module. 自定义模块:这也可以通过自定义模块轻松完成。 As this answer here recommends 正如这个答案在这里建议

function yourmodule_block_view($delta='')
{
  switch($delta) {
    case 'your_block_name':
      $block['subject'] = null; // Most forms don't have a subject 
      $block['content'] = drupal_get_form('yourmodule_form_function');
      break;
   }
   return $block;
 }

the form array returned by drupal_get_form will be automatically rendered. drupal_get_form返回的表单数组将自动呈现。

yourmodule_form_function is a function (in your module or an existing Drupal module) that returns the form array; yourmodule_form_function是一个函数(在您的模块或现有的Drupal模块中),用于返回表单数组;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM