Skip to content
Advertisement

How to get properties of Contact Form 7 object in PHP

I’m trying to manipulate some of the mark-up for a contact form on my site, and have managed to get the specific object I want using

        $forms = WPCF7_ContactForm::find(array('p' => $redirect['form']));

I have no idea what the ‘p’ key is or why it works, but nothing else seems to.

It returns this object:

object(WPCF7_ContactForm)#6114 (9) { ["id":"WPCF7_ContactForm":private]=> int(383) 
["name":"WPCF7_ContactForm":private]=> string(8) "untitled" 
["title":"WPCF7_ContactForm":private]=> string(15) "Customer Survey" 
["locale":"WPCF7_ContactForm":private]=> string(5) "en_GB" 
["properties":"WPCF7_ContactForm":private]=> array(5) { ["form"]=> string(2119) " (really long 
form string) "

The form string is the part i want to manipulate to add HTML to it. I do know you can add things like ID’s and classes in the editor but that isn’t what I’m after. My understanding of objects or arrays within objects has me stumped of just how to access the values here.

Advertisement

Answer

The form string is the part i want to manipulate to add HTML to it.

much easier to do it at the DB level. The CF7 form stores its meta-data and HTML form as a custom post type wpcf7_contact_form along with a number of meta fields.

The form string you’re after can be retrieved from the post meta-field table using the form id,

$form = get_post_meta($form_id, '_form', true);
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement