Extra Block Types (EBT) - New Layout Builder experience❗

Extra Block Types (EBT) - styled, customizable block types: Slideshows, Tabs, Cards, Accordions and many others. Built-in settings for background, DOM Box, javascript plugins. Experience the future of layout building today.

Demo EBT modules Download EBT modules

❗Extra Paragraph Types (EPT) - New Paragraphs experience

Extra Paragraph Types (EPT) - analogical paragraph based set of modules.

Demo EPT modules Download EPT modules

Scroll

Drupal WebForm Module. Creating a product order form

17/04/2025, by Ivan

Let's return to our product catalog, which we created in one of the previous lessons. The catalog is being filled successfully and is more or less displayed correctly, but ordering a product through the contact form is rather inconvenient — you have to copy the name, product code, then paste it into the form and write a message. Let's create a form that simplifies the ordering process. For this, we will need the Webform module, which is used for creating forms in Drupal. Through the form, we will transmit the product name and quantity. If you also need the product code, you can pass that as well by analogy.

Download and install the Webform module.

After installation, a new content type Webform should appear. Create a new node of type Webform, name it Product Order Form (or any other name you prefer). After creating it, you will be redirected to the webform node configuration page.

We need to create two fields for the product name and its quantity. For this, we will use two textfields.

In the product name field, enter %get[product]

Drupal webform

For the quantity field, set the default value to "1".

Also add a text field for the email and another text area for client notes and preferences.

%get[product] is similar to the PHP variable $_GET['product'], which retrieves a value from the URL.

The form is ready. Now we need to create a link to this form and append the product parameter to the link, which will contain the product name. We'll format this link as a separate block that will be displayed at the bottom of each product node.

To perform the following operations, you need to enable the built-in PHP filter module, which allows inserting PHP code directly into a block or content. After enabling this module, a new input format named PHP code should appear.

Create a new block and select the PHP code input format. Paste the following code into the block content:

<a href="<?php print base_path(); ?>node/6?product=<?php print drupal_get_title(); ?>">Order this product</a>

Here, node/6 is the node path of the product order webform.

The function drupal_get_title() returns the node title, which in our case is the product name. The function base_path() returns the base path of the site (e.g., drupalbook.org/). Now, we need to place the block in the Content region. Set the following visibility settings in PHP mode:

$types['tovar'] = 1;
$match = false;
if ((arg(0) == 'node') && is_numeric(arg(1))) {
  $node = node_load(arg(1)); 
  $match = isset($types[$node->type]); 
} 
return $match;

Here, tovar is the machine name of the content type "Product".

Our product order form is now ready.