• Resolved sipitai

    (@sipitai)


    Hello,

    Is there a hook I can use in CF7 to modify the fields of the outputted form? More specifically their default values?

    For example say I have the following field [text text-1 "ABC"] and I want to add a function (in functions.php) that would change the default value to “DEF” (based on a set of conditions), is there a hook I can use to do this?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Takayuki Miyoshi

    (@takayukister)

    You can use wpcf7_form_tag filter.

    Thread Starter sipitai

    (@sipitai)

    Thanks! That’s what I was looking for.

    Are these hooks documented somewhere, or is it just a matter of searching the code for them?

    Here’s an example function for future readers:

    function example_wpcf7_form_tag( $scanned_tag, $replace ) { 
    	if ( $scanned_tag["name"] == 'example-fieldname' ) {
    		$new_value = "Example Text";
    		$scanned_tag["values"] = array($new_value);
    	}
    	return $scanned_tag;
    }; 
    add_filter( 'wpcf7_form_tag', 'example_wpcf7_form_tag', 10, 2 );
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Hook to modify outputted form fields’ is closed to new replies.