我有一个带有一堆输入的前端形式。我的要求迫使我使用自定义短代码来创建表单。我已经测试了该快捷代码的页面。

这是我的:

<form name="myform" method="post" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>" enctype="multipart/form-data">

基于此,它应该打开同一页面(并且确实如此)。但是,当我击中提交时,我在相同的URL上获得了404。有解决方案吗?

更新#1

我使用add_action('init')尝试不同的路线:

add_action('init', 'mbro1_intercept_form_input');
function mbro1_intercept_form_input()
{
    if( !(isset($_POST['action_code']) && $_POST['action_code'] == 'mbro_intercept_form_input') )
        return "";
    if( isset( $_POST['submit'] ) )
    {
        //do my code here
        wp_redirect( get_permalink(35) );//page that has [shortcode]
    }
}

这成功实施了我在提交方面的预期行动。但!重定向后,它仍然有404。我不知道怎么了。

有帮助吗?

解决方案 3

我拿 die() 作为解决方案。不过,我不喜欢这个。

$redirect_link =  get_permalink(35) ; //page that has form
$script_redirect = "<div>Your form is submitted. Please wait a moment. If your browser didn't redirect, click <a href='$redirect_link'>here</a>.</div>
<script type='text/javasript' language='javascript'> 
    window.location = '$redirect_link';
</script> ";
die( $script_redirect );

其他提示

您的表格是否具有名称为“名称”的输入?例如:

<input type="text" name="name">

如果是这样,那将引起麻烦。更改名称值。

另请参阅: 形式“名称”中断,转到404页.

我假设末端的线

wp_redirect( get_permalink(35) );//page that has form

是失败的。我会将其更改为

$redirect_link =  get_permalink(35) ; //page that has form
wp_redirect( $redirect_link );  // trigger redirect
exit;

这应该使其运作正常

许可以下: CC-BY-SA归因
scroll top