What is this? From this page you can use the Social Web links to save Tiny Scripts for “Stealth” Form Submissions to a social bookmarking site, or the E-mail form to send a link via e-mail.

Social Web

E-mail

E-mail It
June 20, 2007

Tiny Scripts for “Stealth” Form Submissions

Posted in: Business Tools

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″.


Return to: Tiny Scripts for “Stealth” Form Submissions