Cookie redirection issue after submit (form)

I have an issue with a redirect I am trying to add on a website. I am not a big expert so that’s why I am asking for kind help.

Before showing the code here are the issues, and how I wanted this to work.

So, I have an Aweber form added to my site with two fields Name and Email + the submit button. Basically, if a submission is successful the user would be redirected to another page and a cookie would set in.

What’s with the cookie?

Well the form is on website.com, and if a user gets subscribed he is redirected website.com/whatever.html

Also, if he subscribed, the next time he enters website.com he will be automatically redirected on website.com/whatever.html

Ok, so I got this main idea to work but I have an issue with it working correctly.

Basically, now it redirects the user even if he enters incorrect details, like Name: JHKJHKhj and Email: jkhkjhkjhkhjk

If he enters these details like that (incorrectly) he should get on the error page which is set by Aweber, but now he gets redirected anyways.

So this is how this should work :

  1. User enters details properly, he gets redirected and cookie sets in.
  2. User enters details incorrectly, he gets the default Aweber error page and he is not redirected.

Here is my code now:



    >      $(document).ready(function() {
    >         $('#subscribe1').show()
    >
    >           if (!readCookie('hide')) {
    >           }
    >
    >           else {
    >             window.location = "http://website/whatever"
    >           }
    >
    >
    >           $('#sendbtn').click(function() {
    >             window.location = "http://website/whatever"
    >             createCookie('hide', true, 365)
    >             return false;
    >           });
    >
    >         });
    >
    >
    >
    >         function createCookie(name,value,days) {
    >           if (days) {
    >             var date = new Date();
    >             date.setTime(date.getTime()+(days*24*60*60*1000));
    >             var expires = "; expires="+date.toGMTString();
    >           }
    >           else var expires = "";
    >           document.cookie = name+"="+value+expires+"; path=/";
    >         }
    >
    >         function readCookie(name) {
    >           var nameEQ = name + "=";
    >           var ca = document.cookie.split(';');
    >           for(var i=0;i < ca.length;i++) {
    >             var c = ca[i];
    >             while (c.charAt(0)==' ') c = c.substring(1,c.length);
    >             if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    >           }
    >           return null;
    >         }
    >
    >         function eraseCookie(name) {
    >           createCookie(name,"",-1);
    >         }

And here is a part of the Aweber code

 <form method="post" class="af-form-wrapper" action="http://www.aweber.com/scripts/addlead.pl"  >
    <div style="display: none;">
    <input type="hidden" name="meta_web_form_id" value="522321120" />
    <input type="hidden" name="meta_split_id" value="" />
    <input type="hidden" name="listname" value="jenselter" />
    <input type="hidden" name="redirect" value="http://website.com/whatever" />

    <input type="hidden" name="meta_adtracking" value="My_Web_Form" />
    <input type="hidden" name="meta_message" value="1" />
    <input type="hidden" name="meta_required" value="name,email" />

    <input type="hidden" name="meta_tooltip" value="" />
    </div>

Thanks !

You did not described how the login and password are checked. The code you posted only reacts on the button click directly, without any checks. So it sets the cookie and redirects user but the credentials are not verified. How do expect them to be verified?

Ok, so the code for the form is generated automatically by Aweber. This wouldn’t have been my choice but this is how I got it.

Here is the whole code I got for this

<form method="post" class="af-form-wrapper" action="http://www.aweber.com/scripts/addlead.pl"  >
<div style="display: none;">
<input type="hidden" name="meta_web_form_id" value="522321120" />
<input type="hidden" name="meta_split_id" value="" />
<input type="hidden" name="listname" value="jenselter" />
<input type="hidden" name="redirect" value="http://www.aweber.com/thankyou-coi.htm?m=text" id="redirect_9fdb1fef967f03c9b582bc463f43b007" />

<input type="hidden" name="meta_adtracking" value="My_Web_Form" />
<input type="hidden" name="meta_message" value="1" />
<input type="hidden" name="meta_required" value="name,email" />

<input type="hidden" name="meta_tooltip" value="" />
</div>
<div id="af-form-522321120" class="af-form"><div id="af-header-522321120" class="af-header"><div class="bodyText"><p>&nbsp;</p></div></div>
<div id="af-body-522321120"  class="af-body af-standards">
<div class="af-element">
<label class="previewLabel" for="awf_field-54960658">Name: </label>
<div class="af-textWrap">
<input id="awf_field-54960658" type="text" name="name" class="text" value=""  tabindex="500" />
</div>
<div class="af-clear"></div></div>
<div class="af-element">
<label class="previewLabel" for="awf_field-54960659">Email: </label>
<div class="af-textWrap"><input class="text" id="awf_field-54960659" type="text" name="email" value="" tabindex="501"  />
</div><div class="af-clear"></div>
</div>
<div class="af-element buttonContainer">
<input name="submit" id="af-submit-image-522321120" type="image" class="image" style="background: none;" alt="Submit Form" src="http://www.aweber.com/images/forms/marla/submit.png" tabindex="502" />
<div class="af-clear"></div>
</div>
<div class="af-element privacyPolicy" style="text-align: center"><p>We respect your <a title="Privacy Policy" href="http://www.aweber.com/permission.htm" target="_blank">email privacy</a></p>
<div class="af-clear"></div>
</div>
<div class="af-element poweredBy" style="text-align: center; font-size: 9px;"><p>Powered by AWeber <a href="http://www.aweber.com" title="Email Marketing Tools">Email Marketing Tools</a></p>
<div class="af-clear"></div>
</div>
</div>
<div id="af-footer-522321120" class="af-footer"><div class="bodyText"><p>&nbsp;</p></div></div>
</div>
<div style="display: none;"><img src="http://forms.aweber.com/form/displays.htm?id=rExMzEyMjEwM" alt="" /></div>
</form>
<script type="text/javascript">
    <!--
    (function() {
        var IE = /*@cc_on!@*/false;
        if (!IE) { return; }
        if (document.compatMode && document.compatMode == 'BackCompat') {
            if (document.getElementById("af-form-522321120")) {
                document.getElementById("af-form-522321120").className = 'af-form af-quirksMode';
            }
            if (document.getElementById("af-body-522321120")) {
                document.getElementById("af-body-522321120").className = "af-body inline af-quirksMode";
            }
            if (document.getElementById("af-header-522321120")) {
                document.getElementById("af-header-522321120").className = "af-header af-quirksMode";
            }
            if (document.getElementById("af-footer-522321120")) {
                document.getElementById("af-footer-522321120").className = "af-footer af-quirksMode";
            }
        }
    })();
    -->
</script>

The code is ok but it does not answer on the question what do you mean in your first post by “User enters details incorrectly”. What does the “incorrectly” means in your case?

Ok, let me show you what I mean.

I uploaded the form on a server to see exactly. You can find it http://stilbarbatesc.ro/aweber/

So if you fill in the email address with something like asdasdasd you are redirected to an error page.

Good, now, the script I put in my initial post, with the redirect + cookie, does the redirect even if somebody fills the email in that way and this shouldn’t happen.

If a user enters Email: adasdas he should get that error page instead of being redirected because that’s not a valid email address.

If he enters a Email: example@example.com he should be redirected and the cookie should set in.

In Aweber’s provided html code there is a line

<input type="hidden" name="redirect" value="http://website.com/whatever" />

So basically that value should be set somehow within JS. If it turns out true (name + valid email) it should pop in the cookie + redirect. If it turns out false (invalid email) you should get the error page and be able to fill the form again so no redirect and cookie.

I didn’t manage to get this working, the thing you told me about in the PM.

I was thinking and searching for a simpler solution but didn’t find one to fit my needs.

Anyway I did remove the script from the page. Now if you enter an invalid email you get the error page, and if you enter a valid email you get redirected to a specific page set by me.

This redirection thing comes from

<input type="hidden" name="redirect" id="redirect" value="http://website.com/whatever" />

So I don’t know if there would be a much simpler solution to create something based on that. The user to be redirected to that page if the action is successful and the cookie set which would always redirect him to that certain page.

Waiting for some suggestions