filter/action to replace form content
-
I wrote a plugin where I use a function to replace the form tags for certain forms:
add_action('wpcf7_before_send_mail', array( $this, 'changemail'), 10, 1);The function gets the form by name, and then modifies the mail output:
$submission = WPCF7_Submission::get_instance(); $main_mail = $contact_form->get_properties( 'mail' ); if(in_array($contact_form->title, array("Questionnaire"))){ $main_mail['mail']['body'] = "[your-message]"; $contact_form->set_properties( array( 'mail' => $main_mail['mail'] ) ); }This is simplified, but you get the idea. No matter what is actually entered in the CMS, if the form is named “Questionnaire”, the output is whatever the user entered in the ‘your-message’ field.
I want to also do this with the rendering of the form itself. No matter what the user has put in the form template, in the CMS, I still want the output to be, for instance, [textarea your-message].
I’ve tried using the filter wpcf7_form_elements, and this will replace the form. However, this is the rendered output. So [textarea your-message] will literally render that in the page, and not <textarea name=”your-message”>.
I need to be able to alter the pre-rendered form, where the template tags can still be rendered later. How do I do this?
The topic ‘filter/action to replace form content’ is closed to new replies.