单击表单提交按钮时重定向


Redirect when form submit button is clicked

我有这个代码,它可以工作,用户登录成功,但我也需要这样做,以便一旦登录他就会被重定向到另一个页面,我对php不是很熟悉,我在这里和谷歌上看了一下,并在提交时进行重定向我看到你改变了action="目标网址",但它已经包含了那个php代码,如果我改变它不起作用。我感谢任何和所有的帮助。

<div id="apDiv4">
<form name="login-form" id="sidebar-login-form" class="standard-form" action=" <?php echo site_url( 'wp-login.php', 'login_post' ) ?>" method="post">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td><table width="100%" border="0" cellspacing="0" cellpadding="5">
       <tr>
          <td>
        <label><?php _e( 'Username', 'buddypress' ) ?>
        <input type="text" name="log" id="sidebar-user-login" class="input" value="<?php echo esc_attr(stripslashes($user_login)); ?>" /></label>
           </td>
          <td>
        <label><?php _e( 'Password', 'buddypress' ) ?>
        <input type="password" name="pwd" id="sidebar-user-pass" class="input" value="" /></label>
           </td>           
        </tr>
        <tr><td>
        <p class="forgetmenot"><label><input name="rememberme" type="checkbox" id="sidebar-rememberme" value="forever" /> <?php _e( 'Remember Me', 'buddypress' ) ?></label></p></td>
                <td>
                <?php do_action( 'bp_sidebar_login_form' ) ?>
                <input type="image" value=<img src="http://anime.edgardoroldanonline.com/wp-content/themes/buddyboss-child-fixed-navbar/images/button-letmein.png" width="127" height="26" name="wp-submit" id="sidebar-wp-submit" tabindex="100" />
                <input type="hidden" name="testcookie" value="1" />
?>
                 </td>
</td>       
        </tr>
      </table></td>
    </tr>
  </table>
            </form>
</div>

当它的wordpress时,你应该在你的表单(redirect_to)中使用一个隐藏的字段。这是一个功能。

<form name="login-form" id="sidebar-login-form" class="stand...
  <input type="hidden" name="redirect_to" value="http://redirect.to.com">

在WP-login的第570行.php它将在登录后处理重定向值:

$redirect_to = apply_filters('login_redirect', $redirect_to, isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '', $user);


旁注:您也可以使用 wp_redirect() 直接调用重定向函数:
<?php
wp_redirect( $location, $status );
exit;
?>
您需要

在处理表单值的 PHP 脚本中使用header("Location: /some/page.php")调用。

此重定向必须在服务器端完成,因为您的服务器首先需要实际接收数据,因此您无法更改操作字段。

在你处理事务的 php 文件中,你可以使用 header-location:

<?php
$host  = $_SERVER['HTTP_HOST'];
$uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/''');
$extra = 'some_page.php';
header("Location: http://$host$uri/$extra");
?>