【问题标题】:How to link contact form 7 values stored in the database to a specific user - Wordpress如何将存储在数据库中的联系表格 7 值链接到特定用户 - Wordpress
【发布时间】:2021-04-14 10:11:55
【问题描述】:

我创建了一个联系表格 7 多步骤表格(4 个步骤)并安装了一个插件来将值保存到数据库中。我还可以看到保存在数据库中的值。

我想要在用户个人资料中将这些问题显示为可编辑版本,以便用户可以编辑他在所有 4 个表单中输入的详细信息,这应该在数据库中更新。

现在我正在使用终极会员插件进行用户注册。这很好用,但我不知道如何将用户与他的应用程序链接(将用户链接到数据库中保存的表单值,以便我可以为每个用户相应地显示值)

我对 wordpress 完全陌生。任何帮助将不胜感激。谢谢!

【问题讨论】:

    标签: wordpress contact-form-7 ultimate-member


    【解决方案1】:

    我会将Smart Grid Layout extension 用于CF7 和Post My CF7 Form extension 的组合,因为两者相互兼容。

    智能网格插件允许您使用单个表单结构(而不​​是单独的表单)构建多步骤表单,使用滑块显示或手风琴。要了解如何使用智能电网构建多幻灯片表单,请参阅此video tutorial。

    Post My CF7 表单允许您将表单映射到帖子(或自定义帖子(而不是在数据库中创建一个表。这样做的好处是每个被保存到帖子的子表单也关联登录用户作为帖子的作者。

    如果您的用户可以访问您网站的仪表板,他们可以使用帖子编辑器编辑他们的帖子,否则如果您需要他们在前端编辑帖子,插件可以重新加载已保存的帖子并将其值转换为给定用户的表单,您可以使用以下过滤器来实现此目的,

    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;
    }
    

    【讨论】:

    • 非常感谢。我会试试这个!
    猜你喜欢
    • 1970-01-01
    • 2018-12-29
    • 2018-10-18
    • 2014-05-31
    • 1970-01-01
    • 2015-09-22
    • 2018-06-23
    • 1970-01-01
    • 2016-04-20
    相关资源
    最近更新 更多