Load default values (pre-fill form)
-
Hello,
first of all, thank you for the great plugin!!! Such a time saver!
I dont get it how to pre fill the form.
I have a form with this shortcode “[cf7form cf7key=”ohne-titel_copy”]”If I try to use your example code in my functions.php it does nothing and I cant find the failure. Maybe you can help?
$content = get_the_content(); //let's find our shortcode preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches ); $args = array(); if( isset( $matches[2] ) ){ foreach( (array) $matches[2] as $key => $shortcode ){ if( 'contact-form-7' === $shortcode ) //do I need to change this to "ohne-titel_copy"? --> Already tried but did not help $args[] = shortcode_parse_atts( $matches[3][$key] ); } } //here I am assuming there is a single form on the page, if you have multiple, you will need to loop though each one if(!empty($args) && isset($args[0]['id'])){ $short_id = $args[0]['id']; $values = array(); if(is_user_logged_in()){ $user = wp_get_current_user(); $values['your-name']= $user->display_name; $values['post-id']= get_the_ID(); //now lets filter the values add_filter('cf7_2_post_form_values', function($field_values, $cf7_id) use ($short_id, $values){ if($short_id == $cf7_id ){ return $values; } }, 10,2); } }
I’m pretty sure it’s just something small that I’m missing?!
BR;
NikoThe page I need help with: [log in to see the link]
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Load default values (pre-fill form)’ is closed to new replies.