Modify form data before it is processed

This documentation page is for Quform version 1 and may not be applicable for Quform 2 click here to visit the documentation for Quform 2.

In this guide we will create a PHP function that will alter two of the form fields before the form is processed. We will modify the “First name” and “Last name” fields of the form and force the text to be uppercase.

Step 1

Get the unique ID of your form, see Finding the form ID.

Step 2

Get the unique IDs of the “First name” and “Last name” fields of the form, see Finding the unique element ID.

Step 3

Add the following code to the wp-content/themes/YOUR_THEME/functions.php file (or create a plugin for it).

1
2
3
456
7
8
91011
12
13
function my_alter_form_values($form)
{
    // Set the first name value to uppercase
    if (isset($_POST['iphorm_1_1'])) {        $_POST['iphorm_1_1'] = strtoupper($_POST['iphorm_1_1']);    }
 
    // Set the last name value to uppercase
    if (isset($_POST['iphorm_1_2'])) {        $_POST['iphorm_1_2'] = strtoupper($_POST['iphorm_1_2']);    }
}
add_action('iphorm_pre_process_1', 'my_alter_form_values');
function my_alter_form_values($form)
{
    // Set the first name value to uppercase
    if (isset($_POST['iphorm_1_1'])) {
        $_POST['iphorm_1_1'] = strtoupper($_POST['iphorm_1_1']);
    }

    // Set the last name value to uppercase
    if (isset($_POST['iphorm_1_2'])) {
        $_POST['iphorm_1_2'] = strtoupper($_POST['iphorm_1_2']);
    }
}
add_action('iphorm_pre_process_1', 'my_alter_form_values');

Modify the highlighted lines to suit your form setup.

  • On lines 4 and 5, change iphorm_1_1 to the unique ID of the “First name” element
  • On lines 9 and 10, iphorm_1_2 to the unique ID of the “Last name” element
  • On line 13, change the number 1 to the form unique ID

Step 4

Save the file and upload it to your web server.

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