QuestionsCategory: Technical QuestionSet field values of contact form 7 in functions.php?
Faiza Abdullah
asked 1 year ago

I want to set field values of contact form 7 in function.php. Here is my code in function.php.



1 Answers
tech Staff
answered 1 year ago
Hi,
You can initially in the form fieldset a unique text, and then use the hook to replace it with the desired value. And then no plugin will be needed.
Example. In form code:

<label>Name</label>
[text Name "NAME_VALUE"] 

in functions.php:

add_filter( 'wpcf7_form_elements', function( $form ) {
  $form = str_replace( 'NAME_VALUE', $_GET['name'], $form );
  return $form;
} );

in URL:

your-site.com/page?name=1



Your Answer