Using Dynamic Values in Contact Form 7

Using Dynamic Values in Contact Form 7

This is one of cool features like we have a site where we have surgeons stored in custom post type and each surgeon has its own detail page and corresponding appointment form so if there are 100 surgeon we are not going to create 100 forms so here is the cup of tea.

/*Add dynamic value to contact form 7*/
add_filter( 'shortcode_atts_wpcf7', 'custom_shortcode_atts_wpcf7_filter', 10, 3 );
function custom_shortcode_atts_wpcf7_filter( $out, $pairs, $atts ) {
    $customattr = 'destination-email';
 
    if ( isset( $atts[$customattr] ) ) {
        $out[$customattr] = $atts[$customattr];
    }
     return $out;
}
/*Add dynamic value to contact form 7*/

screen48

The code on the template file

screen49

The contact form field in green

screen50

Leave a Reply

Your email address will not be published. Required fields are marked *