• courageous999

    (@courageous999)


    I am trying to extend the CF7 plugin through their form tag filter to meet my needs, however I have run into a weird case. I have the following function (In my Theme Functions file) that somewhat works:

    function custom_shortcode_handler( $tag, $unused ) {
        $formidable_array = get_related_vars(array('type' => 'cf7'));
    
        if ($tag[name] === 'user') {
            $tag[raw_values][] = $user;
            $tag[values][] = $user;
            $tag[labels][] = $user;
        }
        if ($tag[name] === 'display-name') {
            $tag[raw_values][] = $display_name;
            $tag[values][] = $display_name;
            $tag[labels][] = $display_name;
        }
        if ($tag[name] === 'email') {
            $tag[raw_values][] = $formidable_array[139];
            $tag[values][] = $formidable_array[139];
            $tag[labels][] = $formidable_array[139];
            if (!empty($formidable_array[223])) {
                $tag[raw_values][] = $formidable_array[139].', '.$formidable_array[298];
                $tag[values][] = $formidable_array[139].', '.$formidable_array[298];
                $tag[labels][] = $formidable_array[139].', '.$formidable_array[298];
            }
        }
        if ($tag[name] === 'phone') {
            $tag[raw_values][] = $formidable_array[135];
            $tag[values][] = $formidable_array[135];
            $tag[labels][] = $formidable_array[135];
        }
        if ($tag[name] === 'campaign') {
            $tag[raw_values][] = $campaign_name;
            $tag[values][] = $campaign_name;
            $tag[labels][] = $campaign_name;
        }
    
        return $tag;
    }
    add_filter('wpcf7_form_tag', 'custom_shortcode_handler', 10, 2);

    On the Contact Form 7 side, I have the following fields:

    [text user]
    [text display-name]
    [text email]
    [text phone]
    [text campaign]

    Each one of these text fields is correctly updated by the function above, except for the phone field. I’ve tried switching that field to tel, number, text area, hidden, to no avail. It just doesn’t retrieve the value, but if I replace $formidable_array[135] with any string (that has no numbers) it would work. If I put in any digits, it doesn’t anymore or practically just takes out the digits and leaves the letters.

    Do keep in mind that $formidable_array[135] is not the issue because it can be replaced by any number inside quotes and the output remains the same.

    Something weird to note is that if I were to print out the $tag array within the if-statement as such:

    if ($tag[name] === 'phone') {
                $tag[raw_values][] = $formidable_array[135];
                $tag[values][] = $formidable_array[135];
                $tag[labels][] = $formidable_array[135];
                echo '<pre>';
                print_r($tag);
                echo '</pre>';
            }

    It would print the $tag array twice, first with the correctly inserted phone values (i.e. raw_values, values, and labels all set to ‘1234567890’), followed by a repost with all the values set back to null.

    I am somewhat convinced that they’ve some kind of Regex cleaner within the plugin code for digits for whatever reason but I cannot find it or figure out a way to resolve this.

    Any help is much appreciated.

  • The topic ‘CF7 Dynamically change form data’ is closed to new replies.