开发者

Intended URL redirect upon form submission

I am working on a WordPress site that has a static squeeze page with the plugin "SplashScreen".

The user can choose from two options:

A.) Enter their email address in the form to proceed to the site.

B.) Click a link located under the field which allows them to bypass giving their email.

Curre开发者_Python百科ntly as it stands the user is taken to a thank you page upon giving their email, where they can then click a link to get taken to the home page. Or they are taken directly to the home page if they click the bypass link. However, this only works out well if they came to site directly. If they came to the site from a direct link to a specific post or page they will not be taken back to the page they intended to view originally.

What I am looking to do is have them taken directly to that intended page upon filling out the form or by clicking the bypass link. I have looked everywhere for this and all I can find is information on how to redirect a user back to their intended page after logging in. I know how to do that, this is a bit more complex.

The squeeze page is a simple static HTML page that uses Javascript to set the cookies so the page only appears once:

function setCookie(name, value, expires, path, domain, secure) {
document.cookie = name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
 }

function setsplash() {
var exp = new Date();
var expDays = 365;
exp.setTime(exp.getTime() + (expDays * 24 * 60 * 60 * 1000));
setCookie("splash", "1", exp, "/");
}

And:

<input class="sub-btn-join" type="submit" value="" onclick="setsplash()">

I am open to using whatever works, but Javascript or jQuery would be ideal. Hopefully one of you can help me out on this. I have wasted a lot of time on this.


You can do this in three steps:

  1. Temporarily store the user's URL request in that same cookie. You can get the requested URL with PHP http://$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; or JavaScript (document.URL).
  2. Handle the splash check like you already are with the "splash" cookie.
  3. If the originally-attempted URL is not the home/splash page, use PHP again to redirect to it.

    <?php
        header( 'Location: http://www.example.com/the_page_we_first_wanted.html' ) ;
    ?>
    


While I don't see the code in your question, which will redirect the user somewhere, it is possible to redirect him to the correct page by sending a redirect-header with the new Location. The original location may be read from the $_SERVER['HTTP_HOST'] and $_SERVER['REQUEST_URI']. These should be put on the links / target page of the redirect, which may mean you'll have to edit the SplashScreen-Plugin to send this:

header('Location: '.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);

Bear in mind, that no headers may be send, when some other content has already been send.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜