Contact Form 7
A dropdown listing all forms created in Contact Form 7. Editors pick a form to associate with a page or post without touching shortcodes. Requires Contact Form 7 to be installed and active.
Plugin dependency
This field only appears and functions when Contact Form 7 is installed and active. If CF7 is deactivated, the field dropdown will be empty.
Settings
| Setting | Default | Options | Description |
|---|---|---|---|
| Return Format | id | id · form | id returns the numeric post ID of the form. form returns the full WPCF7_ContactForm object. |
Return values
return_format: 'id'
Returns the form’s post ID as an integer.
$form_id = get_field('page_contact_form');
// 42
return_format: 'form'
Returns a WPCF7_ContactForm object.
$form = get_field('page_contact_form');
// WPCF7_ContactForm object
$title = $form->title(); // "Contact Us"
$id = $form->id(); // 42
Usage
Rendering via shortcode
$form_id = get_field('contact_form');
if ($form_id) {
echo do_shortcode('[contact-form-7 id="' . intval($form_id) . '"]');
}
Rendering with the CF7 API
$form_id = get_field('contact_form');
if ($form_id) {
$form = wpcf7_contact_form($form_id);
if ($form) {
echo $form->form_html();
}
}
Using the form object return format
$form = get_field('sidebar_form'); // return_format: 'form'
if ($form) {
echo '<div class="form-widget">';
echo '<h3 class="form-title">' . esc_html($form->title()) . '</h3>';
echo do_shortcode('[contact-form-7 id="' . intval($form->id()) . '"]');
echo '</div>';
}
Conditional rendering
$form_id = get_field('lead_form');
if ($form_id) {
echo '<section class="cta-section">';
echo '<h2>' . esc_html(get_field('cta_heading')) . '</h2>';
echo do_shortcode('[contact-form-7 id="' . intval($form_id) . '" title="false"]');
echo '</section>';
}