Hi,
I have made a simple script which graps some basic information from linkedin if a user authorize the app. Now with a plain form i now how to prefill the form fields, but i like to use CF7.
What is the best way to prefill a form with CF7??
Any info?
Kevin Ernst
Member
Posted 7 months ago #
Possibly this: Contact Form 7 Dynamic Text Extension.
There also seem to be some ideas here, but they seem to involve hacking at the Contact Form 7 code, which most people will tell you is inadvisable (you lose your changes when the plugin gets updated).
I have to do the same thing with an online (animal) adoptions application. If have any great revelations in the process, I'll post a follow-up here.
guidokritz
Member
Posted 6 months ago #
Hi! You can use this code I wrote. Is kinda hacky but is better than
hacking the plugin core code or rely on javascript tricks. Hope someone find this useful.
function cfvalues( $a ) {
$field_name = 'subject';
$default_value = 'custom';
if ( preg_match_all( '/<input.*?name="' . $field_name . '".*?\/>/', $a, $match ) ) {
$subject = $match[ 0 ][ 0 ];
$new_subject = preg_replace( '/value=""/', 'value="' . $default_value . '"', $subject );
$a = str_replace( $subject, $new_subject, $a );
}
return $a;
}
add_filter( 'wpcf7_form_elements', 'cfvalues' );