I’ve tried using https://www.advancedcustomfields.com/resources/get_field_object/ but that doesn’t contain the form ID inside of it.
Hello, @rtpharry
Add the below code in your current theme functions.php file.
function get_acf_cf7_object() {
return true;
}
add_filter( 'acf_cf7_object', 'get_acf_cf7_object' );
Now you can access contact form 7 object like this
$cf7_form = get_field( 'field_name' );
if ( $cf7_form ) {
echo $cf7_form->id;
echo [contact-form-7 id="$cf7_form->ID" title="Contact form 1"]
}
Thanks
Ohhh! Good idea haha, I forgot about the shortcode.
In my head I was thinking you must be doing some script registration and stuff in the background to inject the form in using your plugin, and it would be complicated to manually inject the form, but it’s all handled by the shortcode.
@rtpharry Please provide the rating to the plugin.
Have a nice day!
Thanks
FYI if anyone else is looking for this, I just tidied up the snippet a bit:
$cf7_form = get_field( 'field_name' );
if ( $cf7_form ) {
echo $cf7_form->id;
echo '[contact-form-7 id="'.$cf7_form->id'." title="Contact form 1"]';
}
hello sir,
In my project “https://snehaclasses.com/download/” we want to download pdf after submit cf7.
we use ACF file field.
on click download button pop bootstrap modal is opne with cf7 after fill cf7 I want to auto download correct file according to subject.
what can I do For this plz help me.
<div class="row">
<?php
wp_reset_postdata();
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args =array(
'post_type' =>array( 'sample_papers'),
'category_name' => 'jee',
'posts_per_page' => -1
);
$postslist = get_posts( $args );
$i = 0;
foreach ($postslist as $post) : setup_postdata($post);
$featuretitle = get_the_title($post->ID);
$post_id = get_the_id();
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' );
$i++;
?>
<tr>
<td> <?php the_field('sample_paper')?></td>
<td>
<div class="col-md-12 d-flex align-items-stretch" >
<div class="modal-toggle" data-toggle="modal" data-target=".modal1<?php echo $i;?>">
<div class="card-body">
<?php
$file = get_field('upload');
if( $file ): ?>
<span data-id="<?php the_ID(); ?>" class="card-title view-post" style="cursor: pointer; position: absulate;right:0 !important;">Download</span> </p>
<?php endif; ?>
</div>
</div>
</td>
</tr>
</div>
<div class="modal modal1<?php echo $i;?>" id="post<?php echo $post_id; ?>">
<div class="modal-dialog modal-lg modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="postModalLabel"><?php the_field('sample_paper') ?></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form action="" method="get" class="php-email-form">
<?php echo do_shortcode('[contact-form-7 id="523" title="Contact form 1"]');?>
</form>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
in function.php I also use
add_action( 'wp_footer', 'example_download' );
function example_download() {
global $post;
return $post->ID;
?>
<script type="text/javascript">
document.addEventListener('wpcf7mailsent', function (event) {
if ('523' == event.detail.contactFormId) {
window.open('<?php the_field('upload', $post->ID);?>',
'_self');
}
}, false);
</script>
<?php
}
Can we do it with ypur plugin plz help me out.
@bharti9107 The plugin is simply providing a field for the admin to select the contact form. Your query is related to a feature you wish to build not a support request/issue with the plugin.
Thank you