More Stealth Links Fun — Questions Answered
Monday, September 10th, 2007After my last post some people observed that if the opt-in form were submitted with incomplete or invalid information, the “thank you” message would still be displayed, and the only way to get the form back would be to reload the page.
Good observations.
Now, comprehensive “form checking” Javascript code is beyond the scope of this blog, but I did create a simple example of how it could be done on the form I showed you last week.
To see the new version, click here to open the page in a new window. Then open up the source code and follow along as I explain the changes I have made
First, not the opening FORM tag — it now includes “name” and “id” attributes, both set to “aform”. There’s nothing special about “aform”, any value would work, such as “theform”, “coolform”, “irock” or even “whatever”. But you’ll see where we reference the form name in a minute.
Now, look at the end of the page (source code), just before the closing BODY tag. You’ll see this little line of Javascript code:
formcode = document.getElementById(’formdiv’).innerHTML;
With this code, I’m just saving the “original” HTML code in the formcode DIV, so I can restore it after it’s been changed by the rmform() (”remove form”) function.
The rmform() function has changed slightly — the HTML code that I assign to the formdiv DIV’s innerHTML now includes this code:
<font size=-1><center>(<A href=”javascript:void” onClick=”document.getElementById(\’formdiv\’).innerHTML = formcode;”>Resubmit Form</a>)</center></font>
So if someone does get a bad value through, and they realize that and want to change it (resubmit the form with a good value), then they just have to click on the “Resubmit Form” link to bring back the original form HTML code.
Now, to minimize the likelihood of a bad value getting through, I added some form field input checking to the “wait” routine. Originally, these were the only two lines there:
string=”rmform();”;
setTimeout(string,delay);
But if you look at the source code, you’ll see there’s a bit more to it now . . .
And lastly, I changed the form “onSubmit” attribute from this:
onSubmit=”wait(3000);”
to this:
onSubmit=”return wait(3000);”
This makes it so the form is only submitted to Aweber IF the “wait” function returns a “true” value. Which won’t happen unless the name and email fields pass the input checking I added.
So there you are . . . if someone submits obviously bad data (blank fields or invalid email format), they will get an error message from their browser. If they submit what looks like legitimate information, but get an error from the Aweber service, the form fields MAY still be replaced with the thankyou message, but they can click on the link to get the form back.
Best,
Paul
P.S. Yanik has a couple more content videos on that site now — check them out here: