Contact form 7 set field value with get request

Contact form 7 set field value with get request

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Contact Form 7 Set Field Value with GET Request

When you navigate to example.com/subscribe/?email=asfafs, your goal is often to have a contact form automatically populate that email address upon loading. This pattern is common in lead magnets or subscription pages where pre-filling data reduces friction for the user. However, implementing this with Contact Form 7 requires understanding how WordPress handles URL parameters and how the plugin interacts with them.

The core issue arises because standard HTML forms are designed to submit data via POST requests. When a page loads, it is typically rendered in response to a GET request. If your form contains an input field intended to capture the email query parameter directly, you cannot simply wrap that field in a PHP block like <?php echo $_GET['email']; ?> inside the shortcode syntax [text* input-name]. The Contact Form 7 shortcode parser expects specific attribute formats (like placeholder, size, or readonly) and will not execute arbitrary PHP code within its definition. Attempting to inject server-side logic directly into the form field definition is the most common pitfall here.

To achieve dynamic pre-filling, you must look at how WordPress exposes URL data to templates. The standard approach involves using the wpforms or native WordPress template tags, but for Contact Form 7 specifically, the plugin architecture relies on a different mechanism.

If you install a plugin that claims to map GET parameters directly to form fields, such as those referencing legacy solutions from sites like Element Design LLC, you may encounter issues where the values simply do not appear. These plugins often attempt to hook into wpforms or contact_form7_pre_send_mail, which can be fragile if the underlying shortcode attributes don't match exactly. In many cases, these custom solutions fail because they try to parse the form output string rather than intercepting the rendering phase before the HTML is sent to the browser.

A more robust solution without relying on third-party plugins is to use the wpforms action hooks or a small snippet of code that targets the specific input ID generated by Contact Form 7. You can hook into the wp_footer or init action to check for the presence of the query parameter and then manipulate the DOM element directly using JavaScript, or you can use an action filter on the shortcode itself if you control the theme's enqueue scripts.

For example, you can add the following code to your functions.php file:

add_action( 'wp_footer', 'cf7_prepopulate_email' );

function cf7_prepopulate_email() {
    // Check if the 'email' parameter exists in the URL
    if ( isset( $_GET['email'] ) && ! empty( $_GET['email'] ) ) {
        $value = sanitize_text_field( $_GET['email'] );
        
        // Find all input fields with the specific name attribute
        foreach ( wpforms()->get_fields() as $field ) {
            if ( $field->name == 'input-name' ) {
                // Note: This is a conceptual example. Actual implementation 
                // often requires targeting by ID or using direct DOM manipulation
                // because CF7 field names are dynamic based on the shortcode.
                echo '<script>document.querySelector(\'[name="input-name"]\').value = "' . $value . '";</script>';
            }
        }
    }
}

However, a cleaner method involves using the wpforms filter specifically designed for this: contact_form7_shortcode. You can inject the value directly into the shortcode by modifying it before rendering. If you have access to the theme files or are using a child theme, you can replace the shortcode call with a version that includes the pre-filled attribute.

Another reliable pattern is to use the wpforms action hook wpforms_before_form if your specific Contact Form 7 setup supports it, allowing you to inject the value into the HTML string of the form before it is outputted. This ensures the browser receives the value attribute already set in the HTML markup, bypassing any potential JavaScript execution blocks or plugin conflicts.

If third-party plugins continue to fail, switching to a lightweight snippet that targets the specific input element by its generated ID (which you can inspect via browser developer tools) is often the most maintainable solution. This avoids dependency on potentially outdated plugin code and gives you precise control over how the URL parameter translates into form data.

Our network