简体   繁体   中英

redirecting users after successful form submission

I have a squeeze page form on my website that is generated using the MailPoet newsletter plugin and would like for users to be redirected to a new url after a successful form submission. I found a script that can be used to achieve this but I am also using another plugin to display the form which strips the form id and so it's not working. I have included the form code below:

<div class="margin-top">
    <form action="" method="post"  >
        <input type="hidden" name="form_id" value="2" />
        <input type="hidden" name="action" value="save" />
        <input type="hidden" name="controller" value="subscribers" />
        <input type="hidden" value="1" name="wysija-page" />
        <input type="hidden" name="wysija[user_list][list_ids]" value="1" />
        <input type="text" class="form-control input-lg" name="wysija[user][firstname]" id="nameItem5" value="Enter Your Name..." onfocus="if (this.value == 'Enter Your Name...') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Enter Your Name...';}">
        <input type="text" class="form-control input-lg" name="wysija[user][email]"  id="emailItem5" value="Enter Your E-Mail..." onfocus="if (this.value == 'Enter Your E-Mail...') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Enter Your E-Mail...';}">
        <input type="text" class="form-control input-lg" name="wysija[field][cf_1]" id="extrapop5" value="Enter Your Phone..." onfocus="if (this.value == 'Enter Your Phone...') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Enter Your Phone...';}">
        <input type="text" class="form-control input-lg" name="wysija[field][cf_2]" id="extrapop5" value="Enter Your Website..." onfocus="if (this.value == 'Enter Your Website...') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Enter Your Website...';}">
        <input type="submit" id="listfusion-submit-btn" class="btn-sone btn-block" value="Submit!" />
    </form>       
</div>

If your successful page is different than your submitting page, just add this in the head.

    <script type="text/javascript">
        window.location.href = "http://esfores.com/tribune/news"
    </script>

If it's the same page, I would use an if statement and some jquery to recognize if a page element exists or not so that the javascript knows which page it's on.

if ($(selector).length)

This examples recognizes if an element does exist, but you can also do the inverse. Here's a simple example.

<script type="text/javascript">
    if ($YOUR_ELEMENT.length)
    {
        window.location.href = "success_page_path";
    }
</script>

在js中重定向:Window.location.href ='http:www.ex.com';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM