Inserting a form into a block in Drupal?

后端 未结 3 1980
余生分开走
余生分开走 2021-02-02 13:35

Is there any command or method that I can use to insert the contents of a form (e.g. the user registration form) into a block?

3条回答
  •  眼角桃花
    2021-02-02 14:09

    In Drupal 7, it looks like this:

    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.

    yourmodule_form_function is a function (in your module or an existing Drupal module) that returns the form array;

提交回复
热议问题