[SOLVED] [Drupal Webform] Get the nid of the current node where the Webform block is placed

| | 1 min read

Webforms can be placed easily in a block in a Drupal website. You might face a scenario in your Drupal website where you have to place a Webform in a block and you need to get the nid of the node where the Webform block is placed to get an idea of which article the user was reading when they submitted the form. There could be other users for it too. Read on to find out how to implement it.

Follow the steps below to get the nid of the current node where the webform block is placed.

  • Firstly make sure your form has a hidden field
  • Next find out the Webform id
  • Create a custom module and place the following code there. If you already have a custom module place the code there.
  • title;
        }
      }
    }
    ?>
    
  • Just remember to replace the '123456' with your webform_id, 'your_module' with the name of your module and your_form_hidden_field with the form key or your hidden field.
  • Also make sure that you have enabled the "Show all Webform pages in block" checkbox enabled for this to work.

Hope that helps.

The easiest way to solve a Drupal issue is to hand it to the Drupal experts. We can provide a wide range of Drupal services to help you maintain and manage your Drupal websites. Get in touch with us to know more.