Getting form values & data types

This guide will explain how to get access to any submitted form data inside action or filter hook functions.

Get a single form value

In the PHP code you can use the following code, replace 1_3 with the element unique ID.

1
$value = $form->getValue('quform_1_3');
$value = $form->getValue('quform_1_3');

$value now contains the submitted form value for element with the unique ID 1_3. Note that the value of some elements is not a string that can simply be displayed using echo in PHP, see the Data types table below for the data types that will be returned from this function for each element type. To get the result in plain text use getValueText and to get the value for displaying in HTML use getValueHtml (see below).

Get a single form value (as a string)

1
$value = $form->getValueText('quform_1_3');
$value = $form->getValueText('quform_1_3');

$value now contains the submitted form value for element with the element unique ID 1_3 as a string, i.e. array types are converted into strings.

By default array types are joined into a string separated by a comma, you can change the separator by passing the new separator as a second argument.

1
$value = $form->getValueText('quform_1_3', ';');
$value = $form->getValueText('quform_1_3', ';');

Note: when using the hook quform_get_value_text do not use this method inside the function or it will create an infinite loop.

Get a single form value (for safe use in HTML)

1
$value = $form->getValueHtml('quform_1_3');
$value = $form->getValueHtml('quform_1_3');

$value now contains the submitted form value for element with the element unique ID 1_3 as a string for safe use in HTML, i.e. array types are converted into strings and the values are HTML escaped.

Note: when using the hook quform_get_value_html do not use this method inside the function or it will create an infinite loop.

Get all form values

To get all form values use the code below.

1
$values = $form->getValues();
$values = $form->getValues();

$values now contains all the submitted form values in an associative array. The string quform_ then the element unique ID is the array key and the submitted value is the array value. Below is an example of the contents of $values after a form has been submitted.

1
2
3
4
array(
    'quform_1_1' => 'My Name',
    'quform_1_2' => 'me@example.com'
)
array(
    'quform_1_1' => 'My Name',
    'quform_1_2' => 'me@example.com'
)

Data types of the form values

The data types of the form values may vary depending on the type of the element. In the table below the data type for each each element and an example are shown.

ElementTypeExample
Textstring
'Foo'
Textareastring
'Foo'
Email addressstring
'email@example.com'
Select menustring
'Option 1'
Checkboxesarray
array(
    0 => 'Option 1',
    1 => 'Option 2'
)
Radio buttonsstring
'Option 1'
Multiple selectarray
array(
    0 => 'Option 1',
    1 => 'Option 2'
)
File uploadarray
array(
    0 => array(
        'name' => 'file.png',
        'size' => 6464,
        'type' => 'image/png',
        'path' => '/home/example.com/public_html/path/to/the/file.png',
        'url' => 'http://www.example.com/path/to/the/file.png',
        'quform_upload_uid' => '(random string)',
        'timestamp' => 1539615356
    ),
    1 => array(
        'name' => 'second-file.png',
        'size' => 3232,
        'type' => 'image/png',
        'path' => '/home/example.com/public_html/path/to/the/second-file.png',
        'url' => 'http://www.example.com/path/to/the/second-file.png',
        'quform_upload_uid' => '(random string)',
        'timestamp' => 1539615357
    )
)
Datestring
'2017-10-08'
Timestring
'16:58'
Namearray
array(
    1 => 'Prefix',
    2 => 'First',
    3 => 'Middle',
    4 => 'Last',
    5 => 'Suffix'
)

Note that if any part is not enabled in the Name element settings then that part of the value will not be present in the array.

Passwordstring
'Foo'
Hiddenstring
'Foo'
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy