Jayd Saucedo

Blog

AJAX E-mail Submitter Update!
Holy hell! One of the very first things I created after I learned JavaScript is being updated‽ Yes, that's right and to your amazement it has no more features than it did before!

So why am I updating it? Well, as I've already mentioned, it was one of the very first things I created after learning JavaScript, and while tens of thousands of people have apparently downloaded it, the script is, in my now expert opinion, terrible! While it works, it could work better. So I've used the knowledge that I've gained in the last four years since release (holy crap) to make the script something that I wouldn't be embarrassed to show another programmer.

First off, the size: The old script is about 55KB uncompressed. The new script is 5KB. That is 9% of its original size! Keep in mind that I am using all of the same images and the new script has every bit of functionality the old one had. How did I trim so much off? Well, the old script uses the prototype JavaScript library, which was completely unnecessary because not only did I use maybe 3 functions out of the 1 billion it provides, but the functions aren't even that hard to recreate. So getting rid of that file really slimmed it down.

The second thing I did was make it easier to implement onto your site.

Here's what I presented people with in the old script:

if (getcookie("email") != null){
var message = getcookie("email").split(",");
document.write("You have signed up for an e-mail alert succesfully with " +message)
}
else {
document.write('Enter your e-mail address:
') document.write(' ') document.write('
') document.write('
') }

I somehow expected them to find a way to implement that on their site. I can't imagine the number of people that got scared and ran the other way when they saw that. Even I get a little scared, and I wrote it! That's not what I want. I want the opposite of that. I want the process to be friendly!

My new version looks like this:

Sign up for an e-mail alert!

If you're scared by that then you have no business running websites! This is plain old HTML (and some basic JavaScript). This is a massive improvement from before, not only is it easier to implement, but it makes me want to implement it. It's just begging to be pasted somewhere. In fact, I might do that on this site if I find a place where I like it. I bet you're wondering how I could make it so simple but keep the functionality the same. The old script was ugly because it had to decide if it should write the actual form or display a message that said you already signed up. In my new script I moved all that code to an external JavaScript file and improved it so it wrote the form no matter what, but if the script needed to replace the form the script replaced it before you could even think about using it.

Not only that, but I lied about having no more features than before. I get a number of e-mails asking about how one would go about disabling the very functionality I was just talking about; how to disable the feature that prevented people from submitting multiple times. Of course, in my old script it was a horribly complicated process trying to modify it so it worked the way you wanted. Now, all you have to do is set the "enable_cookies" variable to true or false. If that's too complicated for you then you can pay me and I'll take the microsecond of time to do it for you.

The lies continue: I actually have another feature that I implemented; in such the case that you chose to disable the option to prevent multiple submissions, I added a checking mechanism to the PHP file that prevents duplicate e-mails from being submitted. It will even spit an "E-mail already exists in list!" message at you.

The lies continue even more: I have yet another feature that I implemented while writing this! In the old script I instructed people to chmod their e-mail storage text files to something that couldn't be accessed by passers by. Nobody knew how to do this and the method for doing so differed depending on your host. So what I did was have the PHP script that writes the e-mails CHMOD it for you!

I've turned this script into something I might be proud to show another programmer. This is really something I should have done a long time ago. How everyone managed, I'll never know.

For an example form visit here
To download click here
View the original release page (with a lot more information) here
View the read me file (with a whole lot more information!) here