The Multi-Action Form Submission System
A funny thing happened this week.
My niece, Torah, sent me an email asking how to submit a
form to more than one action URL.
She had tried specifying 2 URLs for the <form... action's
value, comma separated and space separated. And she tried
using 2 action attributes in the form tag.
Nothing worked.
So I told her I would look into writing some JavaScript to
do the job.
Two days after Torah's email arrived, someone else sent
an email inquiring about how one would go about submitting
a form to more than one CGI program.
His reply was, "Watch the blog, or the Possibilities ezine,
if you are subscribed. I'm working on a solution for my
niece."
Okay, and this is synchronicity manifested, 2 days after
that, a third email arrived inquiring about a solution to
the problem of submitting a form to more than one URL.
The solution is finished. And today, as this article is
being written, is exactly two days after the latest email.
So I'm wondering if there is a fourth email waiting in the
mailbox for me. We're experiencing high winds in the New
Mexico (USA) desert and had to take the satellite dish
down. It will be tonight before I find out, after the
winds die down and we're reconnected to the Internet.
The solution is over 150 lines of custom-written JavaScript.
I call it the Multi-Action Form Submission system.
The generator at /multiactionsubmit
will help you create your own copy of the javascript code.
Answer a few questions that will customize the JavaScript
for your implementation, click the button, and you'll get
copy 'n paste code along with instructions.
The form is simple and easy. The instructions are simple
and easy. And the JavaScript does a pretty good job.
The Multi-Action Form Submission system can work with forms
that submit method="POST" or method="GET". Whichever method
the form tag specifies is the method that will be used for
all of the URLs the form is to be submitted to.
Although the Multi-Action Form Submission system does a
good job, it has three drawbacks: The user's browser must
be JavaScript-enabled. The JavaScript doesn't know how to
process file uploads. And submissions the JavaScript is
responsible for require the creation of little temporary
popups.
The "JavaScript Required" Drawback
If JavaScript is disabled, only the URL in the form action's
value is submitted to. The JavaScript can't submit to its
URLs because it can't run.
Depending on your implementation, occasional submission to
only the one URL may be acceptable. But if it's not, the
generator can generate code and instructions for requiring
browsers to be JavaScript-enabled before they can be used
to submit your form.
The "No Uploads" Drawback
The inability to handle file uploads lies only with the
JavaScript. The URL in the form's action="___________"
attribute can process the file upload like it normally
would.
What happens is that the URL in the form action's value
gets the upload information, but that information is
omitted when the JavaScript submits the form to its URLs.
The "Popups" Drawback
Because popup blockers are a very real consideration, the
Multi-Action Form Submission system gives you some choices
about how to handle them.
When a popup blocker is spotted, it will, depending on your
answers when you generate the JavaScript:
-
Either give the user a custom message with an
alert box, or remain silent.
-
Either continue processing the form anyway, or
abort further processing.
The system will spot some blocks, but may not be able to
spot them all.
A "No Popup Required" Solution
It is possible to build a CGI program that will bypass the
JavaScript popup requirements. But I hesitate to spend time
building the software without a good idea about what the
demand for it would be.
The 3 inquiries received in 5 days could be an indication
of demand. But these things go in cycles. By the time the
software is built, which could take several weeks, demand
may have fizzled.
Therefore, I've decided to let you tell me.
If you would like a popup-less CGI solution, let me know,
along with what you think you probably would be willing to
pay for it.
Should I receive enough responses with a value that I think
would make it worth putting in the time, I'll make it for
you and let you know when it's ready.
Use the contact form linked from /
For most, the JavaScript will undoubtedly be exactly what
is needed. Go to /multiactionsubmit
and pick up a copy.
Question:
Did you find this article interesting and understandable? How can it be improved?
Your response is anonymous.
When done typing, click anywhere outside the box. [more info]
Will Bontrager
©Copyright 2006 Bontrager Connection, LLC Bontrager Connection, LLC
Please note:
Articles on this website are presented "as is". However -
If you have a question about a CGI script, HTML, CSS, PHP, or JavaScript
Ask one of our Experts and you'll have your answer!
Click here for details.