How to link contact form 7 values stored in the database to a specific user - Wordpress

I have created a contact form 7 multi step form ( 4 steps) and installed a plugin to save the values into the database. I can also see the values saved in the database.

What I want is to display these questions in the user profile as an editable version, so that the user can edit the details he entered in all the 4 forms and this should be updated in the database.

Right now I am using ultimate member plugin for user registration. That works fine but I have no idea on how to link the user with his application (to link the user to the saved form values in database so that i can display the values accordingly for each user)

I am completely new to wordpress. Any help will be appreciated. Thanks!

Upvotes: 0

Views: 1907

Answers (1)

Aurovrata
Aurovrata

Reputation: 2279

I would use a combination of the Smart Grid Layout extension for CF7 and the Post My CF7 Form extension, as the 2 are compatible with one another.

The Smart Grid plugin allows you to build multi-step forms using a single form construct (rather than separate forms), either using a slider display or an accordion. To see how to build a multi-slide form using the Smart Grid, please see this video tutorial.

The Post My CF7 form allows you to map a form to a post (or a custom post( rather than do a table in the database. The advantage of this is that each subitted form being saved to a post is also associating the logged-in user as the author of the post.

If your users have access to the dashboard of your site, they can edit their post using the post editor, else if you need them to edit the post in the front-end the plugin has the ability to reload a saved post and its values into the form for a given user, you can use the following filter to achieve this,

add_filter('cf7_2_post_filter_user_draft_form_query', 'filter_user_post_for_prefill', 10, 3);
/**
* Function to filter the post query for current user in order to prefill form.
* For draft forms (using the save button), this query is configured to load the latest draft submission.
* However, this filter can be used to modify the query for  submitted form that need editing.
* @param Array $query_args array query args for function get_posts().
* @param String $post_type post type being mapped to.
* @param String $form_key unique key identifying the current form.
* @return Array array of query parameters (for more info see the WordPress codex page on get_posts).
*/
function filter_user_post_for_prefill($query_args, $post_type, $form_key){
  //modifying the query to retrieve the last submitted post for the current user.
  //the plugin stores a flag '_cf7_2_post_form_submitted' as a meta field to identiy
  //if a form is submitted or saved as a draft. No for drafts, Yes for submitted.
  $query_args['meta_query']['value']='yes';
  return $query_args;
}

Upvotes: 0

Related Questions