Use Contact Form 7 To Post Rows to Advanced Custom Fields Repeater

April 17, 2015

I was in a particular situation where I needed a task management system that could take fields through a form from Contact Form 7 and post them to rows in the Advanced Custom Fields Repeater field I set up.  The idea was to use a form from the front end of WordPress to post to the back-end of WordPress in a custom field.  You can accomplish this by adding code to your functions.php file in the WordPress theme.

This example assumes that you already have a form set up through Contact Form 7 and you have already purchased the Advanced Custom Fields’ Repeater Field plugin.

1. Get Your Field Key

You can grab your field key from the ACF Repeater Field by selecting ‘Show Field Key‘ from the Screen Options.  You will use this in your function to determine which field to add rows to.

cap1

 

 

2.  Add WPCF7 Before Send Mail Hook

You add the function below to your functions.php file within the theme.  You are hooking into Contact Form 7’s “wpcf7_before_send_mail’ function to grab the post data and post it to a WordPress repeater field as a new row.

Obviously, your fields in the form and the repater field may be different.  The important things to take away from this functions script is that:

You’ve created the hook:

 

You’ve got the URL and ID of the post the form was submitted through:

 

You got the data from the form:

 

And you update the repeater field based on those elements:

Hope that helps!  Don’t forget you can always extend this to a plugin as opposed to a theme function as well.

4 Comments

  • Beetle

    You can also help in this use of the plugin https://wordpress.org/plugins/acf-contact-form-7/

  • rox

    hey !!
    I need to do this urgently in one of my project.I can pay

  • Toplu Sms

    Thank you.

  • Rub

    Hi,
    I understand the development of the solution, but it is not how to apply it.
    Where indicated and print the sub_field ? And if you have sub_field within another sub_field ? Where indicated the id of contact form 7?

    God job, thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *