# formidable/trunk/classes/models/fields/FrmFieldQuantity.php

Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes &amp; More, version trunk. 100 lines.

- Page: https://pluginprobe.com/plugins/formidable/trunk/code/classes/models/fields/FrmFieldQuantity.php
- Raw: https://pluginprobe.com/plugins/formidable/trunk/raw/classes/models/fields/FrmFieldQuantity.php
- Modified: 2026-04-16T12:57:58+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/formidable/trunk/code/classes/models/fields/FrmFieldQuantity.php#L10-L20`.

```php
<?php

if ( ! defined( 'ABSPATH' ) ) {
	die( 'You are not allowed to call this page directly.' );
}

/**
 * @since 6.30 This is copied from FrmProFieldQuantity.php in Formidable Pro.
 */
class FrmFieldQuantity extends FrmFieldNumber {

	protected $type = 'quantity';

	protected function field_settings_for_type() {
		$settings           = parent::field_settings_for_type();
		$settings['unique'] = false;
		$settings['format'] = false;

		return $settings;
	}

	protected function extra_field_opts() {
		return array_merge(
			parent::extra_field_opts(),
			array(
				'product_field' => array(),
				'step'          => '1',
			)
		);
	}

	protected function new_field_settings() {
		return array(
			'default_value' => 1,
		);
	}

	/**
	 * @param array $args - Includes 'field', 'display', and 'values'.
	 */
	public function show_primary_options( $args ) {
		$field = $args['field'];
		// Cast to array because of existing fields that are already using single product fields in production
		$field['product_field'] = $field['product_field'] ? (array) $field['product_field'] : array();
		include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/quantity-options.php';

		parent::show_primary_options( $args );
	}

	protected function html5_input_type() {
		return 'number';
	}

	public function validate( $args ) {
		global $frm_products;
		$parent_errors = parent::validate( $args );

		if ( $parent_errors ) {
			return $parent_errors;
		}

		if ( ! $frm_products ) {
			$frm_products = array();
		}

		$value = trim( $args['value'] );
		$value = is_numeric( $value ) ? $value : 0;

		$product_fields = FrmField::get_option( $this->field, 'product_field' );

		if ( $product_fields ) {
			// Cast to array because of existing fields that are already using single product fields in production
			$product_fields = (array) $product_fields;

			foreach ( $product_fields as $product_field ) {
				$product_field_key = trim( $product_field ) . '_' . $args['parent_field_id'] . '_' . $args['key_pointer'];

				if ( ! isset( $frm_products[ $product_field_key ] ) || ! is_array( $frm_products[ $product_field_key ] ) ) {
					$frm_products[ $product_field_key ] = array();
				}
				$frm_products[ $product_field_key ]['quantity'] = $value;
			}
		} elseif ( ! empty( $args['parent_field_id'] ) ) {
			// Get it ready for the corresponding product field in the row that will use it to calc total
			if ( ! isset( $frm_products['repeat_quantity_fields'] ) || ! is_array( $frm_products['repeat_quantity_fields'] ) ) {
				$frm_products['repeat_quantity_fields'] = array();
			}
			$frm_products['repeat_quantity_fields'][ $args['parent_field_id'] . '_' . $args['key_pointer'] ] = $value;
		} else {
			// This quantity field is in the form but not in a repeater
			if ( ! isset( $frm_products['quantity_fields'] ) || ! is_array( $frm_products['quantity_fields'] ) ) {
				$frm_products['quantity_fields'] = array();
			}
			$frm_products['quantity_fields'][] = $value;
		}//end if

		return array();
	}
}

```
