如何在HTTP POST请求后动态更改网站

时间:2018-02-27 00:13:25

标签: php wordpress forms http-post hook

我一直在尝试在表单提交后动态更改主页,但我不明白为什么它不起作用。

我需要的是在用户选择并提交表单中的某些字段后重定向用户,并将带有HTTP POST的字段发送到另一个页面。如果提交了某些字段,则网站上的所有链接都将更改为与新提交相匹配。

以下是我现在所拥有的。我正在使用联系表单7来构建表单(此表单在主页中):

<div class="home-form">
<div id="region">[select* your-region id:region "Choose a region" "North America" "Latin America" "Europa"]</div>

<div id="language">[select* your-idiom id:language "Choose a language" "Español" "English"]</div>

<div class="submitbutton"><a href="">Go to page</a></div>

</div>

另外,我必须设置一个正确的操作,将此POST发送到我想要的页面,所以我将它添加到functions.php:

//CHANGING ACTION URL
add_filter('wpcf7_form_action_url', 'wpcf7_custom_form_action_url');
function wpcf7_custom_form_action_url($url)
{
    global $post;
    $id_to_change = $pageid;
    if($post->ID === $id_to_change)
        return 'https://website.com/na/';
    else
        return $url;
}

要获得HTTP POST,我只使用此功能:

add_action( 'init', 'get_home_form' ); 

function get_home_form( $contact_form ) {
    $title = $contact_form->title;
    $submission = WPCF7_Submission::get_instance();

    if ( $submission ) {
        $posted_data = $submission->get_posted_data();
    }

   if ( 'Home selection' == $title ) {

        $region = $posted_data['your-region'];
        $idiom = $posted_data['your-idiom'];
    }
} 

直到现在,这不起作用。我在开发工具上的Google网络工具上看到了很多次,检查表单是否已发送到POST而不是。我没有看到请求。

此外,如果我尝试制作并“回显”以检查我是否可以捕获“你的区域”输入并显示它,它也不起作用。

0 个答案:

没有答案