A reader asks:
Not sure this is quite normal, but I have a CF Form, flash format, that based on options selected, submit to different action pages.My Question is, do you know how to access and modify the "action" attribute of a CFForm using ActionsScript from a function in '<cfformitem type="script">' function?
It may very well be possible to change the action of a Flash Form. However, I wasn't sure of how to do that, so I simply used the onsubmit method. Consider the following code block:
<cfform format="flash" width="200" height="200" onsubmit="return goURL()">
<cfformitem type="script">
function goURL() {
var url = destination.value.toString();
getURL(url);
return false;
}
</cfformitem>
<cfselect name="destination">
<option value="http://www.cflib.org">CFLib</option>
<option value="http://www.coldfusioncookbook.com">ColdFusion Cookbook</option>
<option value="http://ray.camdenfamily.com">My Blog</option>
</cfselect>
<cfinput type="submit" value="Go There!" name="submit" />
</cfform>
This relatively simple block of code does a few things. First, it specifies an action to take on form submission. Notice I used "return goURL()" instead of just "goURL()", this was because I wanted the default form submission to not fire. My goURL() function is contained with a script form item block. This is only allowed in ColdFusion 7.0.1. The ActionScript code simply grabs the value of the form below it (which will be a URL), and then calls getURL() to load it.
Archived Comments
Be careful...I don't think using getURL will post the form data (if that is what you're after).
Hi Ray,
I think I found the answer (I didn't want) over on ASFusion, posted by "Laura"
<quote>
You can have a button with onclick="getURL('your page')", appending any data that the page needs (as long as it is short, since it is a get request)
There is no way to change the action page after the form is loaded.
</quote>
Doh!
The way I am doing it now is by passing an attribute and using a <cfswitch> on the action page to decide the action to be taken.
We live an learn!
well i think using a flashform & then submitting it is possibly the wrong way to use flashforms. why not just send the data back via remoting?
That's _definitely_ my preferred way of handling it Paul, but I didn't want to open a can of worms by suggesting that! Remoting gives you infinite possibilities of actions to take and form fields to pass...
Hey Guys,
I am in the process of learning all the remoting tricks, but keep in mind, CFForm is a form, which, by it's very nature, submits data.
So I don't submitting data via a flash form is "wrong".
Any way, I am learngin lots of asfusion, if you guys have any other hot links, that would be great!
Don't get me wrong, I'm not suggesting that posting form data "the old fashioned way" is wrong, I'm just saying that when it comes to more dynamic techniques (such as posting to a dynamic action page), maybe remoting is a cleaner option. ASFusion is probably the best site there is out there right now for taking flash forms to the next level.
...it still blows my mind what the crew at ASFusion is doing with CFForm!
I have lots to learn!
well i am suggesting exactly that, don't use a flashform where it will be submitted. too much overhead, etc. unless the form is pretty complex. i think of flashforms as "flex" not so much as a "form". you can build some cool stuff right now w/a bit of AS & flashforms.