Redirect when form submit button is clicked

2019-08-30 22:47发布

I have this code it works the user logs in successfully but I also need to make it so that once logged in he gets redirected to another page I am not very familiar with php and I have looked around here and with google and to make redirect when submit I saw that you change the action="destination url" but it already has that php code in it and if I change that it does not work. I appreciate any and all help with this.

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

3条回答
迷人小祖宗
2楼-- · 2019-08-30 23:13

As its wordpress your working with you should use a hidden field in your form (redirect_to). Its a feature.

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

on line 570 of wp-login.php it will handle the redirect value after login:

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


Side note: You can also directly invoke the redirect function with wp_redirect():

<?php
wp_redirect( $location, $status );
exit;
?>
查看更多
手持菜刀,她持情操
3楼-- · 2019-08-30 23:28

You're going to want to use a header("Location: /some/page.php") call in your PHP script that processes the form values.

This redirection has to be done server-side because your server first needs to actually receive the data, so you can't change the action field.

查看更多
走好不送
4楼-- · 2019-08-30 23:33

On the php file where you're processing the transaction you could use header-location:

<?php

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

?>
查看更多
登录 后发表回答