Getting form values & data types

This section shows you how to access the form values in the PHP code and can be used in the email content files, database query, Custom code sections #1 & #2 and anywhere else inside the process() function of process.php.

Get a single form value

Use the code below to get a single form value, replace unique_element_name with the unique name of the form element.

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

$value now contains the submitted form value for element unique_element_name

Note: some types of element will return an array and not a string that can be displayed or used without further processing. See the Data types section below for the return types for different elements.

Get a single form value (formatted as Plain text)

Using this code guarantees that the returned value will be a string. Use the code below to get a single form value, replace unique_element_name with the unique name of the form element.

1
$value = $form->getValuePlain('unique_element_name');
$value = $form->getValuePlain('unique_element_name');

$value now contains the submitted form value for element unique_element_name formatted as plain text, this means:

  • Any string types will stay remain the same
  • Any array types will be formatted as a comma separated string. To use a different separator, pass it a second argument e.g. $form->getValuePlain('my_element', ': ');
  • For the Date and Time elements the value will be formatted according to the configured Date/Time formats
  • The value of a File Upload element value will be formatted as the file name and size with a URL after it if the file was saved to the server.

Get a single form value (formatted as HTML)

Using this code guarantees that the returned value will be a string in HTML format. Use the code below to get a single form value, replace unique_element_name with the unique name of the form element.

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

$value now contains the submitted form value for element unique_element_name formatted as HTML, this means:

  • Any string types will stay remain the same, but will be escaped using htmlspecialchars
  • Any array types will be escaped using htmlspecialchars and formatted as separated by the <br> tag. To use a different separator, pass it a second argument e.g. $form->getValueHtml('my_element', ', ');
  • For the Date and Time elements the value will be formatted according to the configured Date/Time formats
  • The value of a File Upload element value will be formatted as the file name and size. If the file was saved to the server it will link to the file.

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 element unique name 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
5
array(
    'name' => 'My Name',
    'email' => 'me@example.com',
    'message' => 'Hello there.'
)
array(
    'name' => 'My Name',
    'email' => 'me@example.com',
    'message' => 'Hello there.'
)

Data types of the form values

ElementTypeExample
Single Line Text
<input type=”text”>
string‘Foo’
Paragraph Text
<textarea>
string‘Foo’
Email Address
<input type=”email”>
string’email@example.com’
Select Menu
<select>
string‘Option 1’
Multi Select Menu
<select multiple name=”foo[]”>
array
1
2
3
4
array(
    0 => 'Option 1',
    1 => 'Option 2'
)
array(
    0 => 'Option 1',
    1 => 'Option 2'
)
Single Checkbox
<input type=”checkbox” name=”foo”>
string‘Option 1’
Multi Checkbox
<input type=”checkbox” name=”foo[]”>
array
1
2
3
4
array(
    0 => 'Option 1',
    1 => 'Option 2'
)
array(
    0 => 'Option 1',
    1 => 'Option 2'
)
Radio Buttons
<input type=”radio”>
string‘Option 1’
File Upload
Quform_Element_File
<input type=”file”>
array
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
array(
    0 => array(
        'url' => 'http://www.example.com/path/to/file.jpg',
        'filename' => 'file.jpg',
        'path' => '/home/example.com/public_html/path/to/file.jpg',
        'type' => 'image/jpg',
        'size'=> 1234
    ),
    1 => array(
        'url' => 'http://www.example.com/path/to/file2.jpg',
        'filename' => 'file2.jpg',
        'path' => '/home/example.com/public_html/path/to/file2.jpg',
        'type' => 'image/jpg',
        'size'=> 4567
    )
)
array(
    0 => array(
        'url' => 'http://www.example.com/path/to/file.jpg',
        'filename' => 'file.jpg',
        'path' => '/home/example.com/public_html/path/to/file.jpg',
        'type' => 'image/jpg',
        'size'=> 1234
    ),
    1 => array(
        'url' => 'http://www.example.com/path/to/file2.jpg',
        'filename' => 'file2.jpg',
        'path' => '/home/example.com/public_html/path/to/file2.jpg',
        'type' => 'image/jpg',
        'size'=> 4567
    )
)
Date
Quform_Element_Date
array
1
2
3
4
5
array(
    'day' => '23',
    'month' => '11',
    'year' => '2015'
)
array(
    'day' => '23',
    'month' => '11',
    'year' => '2015'
)
Time
Quform_Element_Time
array
1
2
3
4
array(
    'hour' => '11',
    'minute' => '58'
)
array(
    'hour' => '11',
    'minute' => '58'
)
Hidden
<input type=”hidden”>
string‘Foo’
Password
<input type=”password”>
string‘Foo’
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy