首页 文章

wordpress表单插件,允许在表单操作中提供自定义URL

提问于
浏览
1

我正在搜索wordpress插件,允许管理员创建一个表单并将该表单提交到自定义URL . 我使用了联系表单7但它不允许这种类型的功能 .

我找到的唯一解决方案是创建自定义表单或使用联系表单7钩子来获取发布数据并通过curl调用将该数据发送到自定义URL .

还有更好的解决方案吗

使用这个小忍者钩,但不工作:

function ninja_forms_handler() {
  add_action ( 'ninja_forms_post_process', 'change_ninja_forms_landing_page', 1, 2 );
}
add_action('init', 'ninja_forms_handler');

function change_ninja_forms_landing_page(){
    global $ninja_forms_processing; 

    $form_id = $ninja_forms_processing->get_form_ID(); 

    $ninja_forms_processing->update_form_setting( 'landing_page', 'test.php' ); 
    }     
}

2 回答

  • 0

    Here I have given two ways by using contact form 7

    Way-1 通过联系表单自定义操作URL

    • 在您的站点根文件夹中创建“custom_url.php”文件在此文件中,您可以获取联系表单发布数据并编写您的卷曲代码以及您想要的任何内容 .

    • 复制以下代码并粘贴到主题function.php文件中

    add_filter('wpcf7_form_action_url', 'wpcf7_custom_form_action_url');
     function wpcf7_custom_form_action_url()
        {
            return 'custom_url.php';
        }
    
    • 将此文件“custom_url.php”提供给联系表单操作 . 复制以下代码并将其粘贴到您的页面中或发布您想要的内容 .

    <form class =“" action=" custom_url.php " method=" post " name="”> [contact-form-7 id = "1" title = "contact form 7"] </ FORM>

    Way-2 虽然联系表格7勾"wpcf7_before_send_mail"

    add_action('wpcf7_before_send_mail', 'CF7_pre_send');
    
    function CF7_pre_send($cf7) {
        $submission = WPCF7_Submission::get_instance();
    
        if ($submission) {
            $posted_data = $submission->get_posted_data();
            $arrFields = array();
            foreach ($posted_data as $key => $value) {
                //$strKeyVals .= $key.":".$value.", ";
                if ("_wp" != substr($key, 0, 3)) {
                    $arrFields[] = $key . '${$' . $value;
                }
            }
    /* Here you can write curl and whatever you want */
    
        }
    }
    
  • 2

    这应该是诀窍CF7 Docs .

    仅将代码添加到“联系”页面模板的页脚 .

    让我知道你是怎么办的 .

相关问题