Provides the Views field which enables to collect user input from HTML form, Webform or exposed filter. Then this data can be used in calculations along with data from other fields. For example, it can be used in a formula of "Views Simple Math Field" module or in Twig (in case of overriding field output).

Uses

Let's say we have the Product content type with the Price field. We need the view where a user can input amount of product units and see the total cost. That is, we need a computed field in which a value of the Pricefield will be multiplied by an amount entered by a user.

1. We can do the calculation with Views Simple Math Field module, so let's install it.

2. To enter the amount of products by a user, we can create either HTML form or Webform (created with Webform module). The HTML form can be created in a custom block or in a view header.

screenshot-1

screenshot-2

3. To get the amount entered by the user, let's add the "Views user input field" field provided by this module.

screenshot-3

Enter the value of "name" attribute of the input element of HTML form created in step 2. In our case the value is "amount".

screenshot-4

In case of getting a value of an exposed filter you should enter the "Filter identifier". And if you need to get the value of Webform element, you should to enter elemen's key (machine name).

4. The last thing we need to do is add a "Simple Math Field" and enter the formula to calculate the total price.

screenshot-5

screenshot-6

screenshot-7

Using Webform

There is the tutorial "How to create a custom Views exposed filter form". But we can use the Webform without exposed filter, similar to how we used the HTML form in step 2. Also, along with the Webform module, we can use the Webform Validation module to validate entered values.

Sponsor
Ölerini

Project information

Releases