Tiny Scripts for “Stealth” Form Submissions
I was actually going to make this part of the last post, but decided it deserved it’s own title . . .
By virtue of the TAFPro and Synergyx software I sell, I do a lot of custom web form code.
Here’s a couple of tricks that have really come in handy lately . . . these aren’t “new”, but are still generally unknown.
Usually when someone clicks the “Submit” button on a web form, their browser loads a new page. But there are times when it’s advantageous to keep them on the same page.
For instance, when someone purchases my resale rights package at pregnancysale.com (and YES, that page is all true, not just some made-up story), they are taken to a download page. On that page I ask them to sign up for my “Updates” list so I can let them know when new software is released.
But I don’t want them to be taken from the download page just to see a “Thank you, you’ve subscribed” message. So what I do is set the “redirect” URL (this is a hidden field in the web form used by Aweber) to a tiny little PHP script on my server called “nonewpage.php”
This is the contents of that script, in its entirety:
<?php
header(”HTTP/1.1 204 No Response”);
?>
This script simply tells the browser, “Nothing to see here — don’t load a new page, stay where you are.”
So all you have to do is copy/paste the above code into your text editor and upload it to your webserver as “nonewpage.php”. Then in your web form, set the redirect URL (most form processing scripts allow you to define where the person goes after they submit the form) to the full URL for that file (e.g. “http://www.yoursite.com/nonewpage.php”).
Now, if you use this, you will WANT to provide feedback to your users when they click the submit button — because if they don’t see the page change, they’ll think that nothing happened. So add an “onClick” attribute to let them know their input was sent . . . something like this:
<input type=”submit” value=”Submit” onClick=”alert(’Thank you! Your feedback is being sent now. \nPlease continue reading (no new page will display’);”>
The “\n” in the message is optional and will simply put the 2nd sentence on a new line.
Now, here’s another trick that has been very useful . . .
Sometimes, for whatever reason, you would like to have a form submit WITHOUT the user clicking on anything.
For example, imagine that your shopping cart displays an interim “confirmation” page requiring people to click the “Continue” button before their credit card is actually charged — and you’ve determined this extra required “click” from the customer is costing you sales (which is very likely BTW).
So you opt to skip the confirmation page and have a “one click” order process instead. Assuming you control the HTML code on the confirmation page, this would be simple to accomplish. Just make all of the form fields on the confirmation page “hidden” and add this bit of javascript directly beneath the closing form tag (”</form”>) :
<script type=”text/javascript”>
<!–
document.orderform.submit();
//–>
</script>
This example assumes the “name” given to the form is “orderform” — if it’s something else, then use that name in the example above instead.
Or if you don’t have that level of control over the page (you can’t change the form name), you can do it this way:
<script type=”text/javascript”>
<!–
document.forms[0].submit();
//–>
</script>
This assumes that it’s the 1st form on your page. If you have multiple forms on the page, and the form you want to “auto-submit” isn’t the first form, then you’ll need to change the [0] to [1] or [2], etc. (0 for the first form, 1 for the 2nd form, etc.).
Now, in MOST cases (not all) you’ll want to include a visible submit button even if you do use the auto-submit code, as some people may have javascript disabled in their browsers. You could just have it say something like, “If this page doesn’t refresh in 5 seconds, please click this button to continue . . .”
Now, think about the combination of the two above scripts . . .
If you had the desired data already, you could post that data to a page without the visitor doing anything.
For instance, you could send out an email to your list and link to a page on your site. The link would include the person’s name and email address, like this http://www.example.com/go.php?e=me@yahoo.com&n=Paul
That page would include PHP code to grab the “e=” and “n=” parameters, and stuff them into hidden form fields on the page. Then your auto-submit Javascript code would submit that data to your autoresponder service or software. And the “nonewpage.php” script would prevent that form post from loading a new page — making the whole process a “stealth” operation.
This would basically allow you to “segment” your general list into several special-interest lists with a single click from each subscriber.
Now, whether this is ethical or not depends on what you tell people in the email before they click the link — and I would definitely encourage full disclosure. But I’m just using this as an example of what you can do with these simple little scripts.
Love it or hate it — let me know what you think!
Paul
P.S. If you’re a TAFPro user, this “nonewpage” capability is built-in. It’s an undocumented feature. Just add a hidden form field to your TAFPro form with a name of “nonewpage” and set its value to “1″.
Share This
June 20th, 2007 at 2:14 am
Thanks for the code. I’m going to test it on my PHP scripts later.
Regards,
Edmund Ng
June 20th, 2007 at 3:07 am
Paul,
That’s something sleek. I’ll try it out later. Thanks.
KokPang
eMoneyWantsYou.com
June 20th, 2007 at 10:23 am
Thanks Paul, Will try this out and let you know the results.
June 20th, 2007 at 10:48 am
Wow, you’ve now finally turned me into a fan.
I love cool little tricks like these. Ever heard of
creating a 1pixel image on your website and
the address for that image is your affiliate link???
So the browser automatically opens the aff.
link when it loads the page thinking that it’s
trying to open an actual image… };-)
Onwards and Upwards,
Justin Brooke
http://www.mpyremarketing.com
June 20th, 2007 at 11:43 am
Hey Paul,
That’s awesome!
I was actually trying to figure out how to do #1 a month or so ago.
Thanks and have a great day!
Mark Meyers
Your VRE Empire
June 21st, 2007 at 10:53 am
Paul,
The info you keep sharing are really great!
Keep up the good work.
Mike
June 22nd, 2007 at 6:40 am
Hi Paul,
Some great info - I’ll have a to have a go with this and see if I can learn a few tricks from you.
By the way - The Traffic generator - Is that based on this new Page curl evryone is selling online? obviously exceptthe one on your page is quite cool because it realises that the reader is leaving and then activates it
Hamant
March 18th, 2008 at 10:37 pm
Thanks Paul - this was VERY handy. Not only did it save me time trying to figure it out, but it also makes the user experience MUCH better for my subscribers. Keep up the great work!
Chris
May 19th, 2008 at 7:30 am
Thanks for the script! it worked for my site..
regards,
Matt