Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create a custom form inside a block in drupal 7

I know how to use a module to create a block and I know how to create a custom form using form api.

now, i want to add this custom form inside the block I create.

like image 264
user1851050 Avatar asked Feb 13 '26 22:02

user1851050


2 Answers

Use the following code (hook_block_view):

 function yourmodule_block_view($delta='') {
     $block = array();
     switch($delta) {
        case 'block_name':
          $block['subject'] = t("Block Title"); 
          $block['content'] = drupal_get_form('your_form_id');
          break;
     }
     return $block;
 }
like image 200
Muhammad Reda Avatar answered Feb 16 '26 18:02

Muhammad Reda


When you create a webform while adding components see the form settings in the upper right:

  1. Click on form settings
  2. Go to advance settings in bottom and click
  3. You find it available as a box checkbox enable that

If enabled this webform will be available as a block.

like image 42
Shreya Shetty Avatar answered Feb 16 '26 19:02

Shreya Shetty



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!