[Looking for Charlie's main web site?]

Posting a form to itself without trickery, using an empty ACTION attribute

Note: This blog post is from 2007. Some content may be outdated--though not necessarily. Same with links and subsequent comments from myself or others. Corrections are welcome, in the comments. And I may revise the content as necessary.
Did you know that if a form has an empty ACTION attribute (or none at all), it will post back to itself (to the page that presented the form)? This can be very useful, and it's a lot easier than more complicated code that struggles to build the ACTION attribute to hold the current filename and any query string.

In the first iteration of this entry, I referred to the two approaches of either providing an empty ACTION or none at all, but as the comments below show, the former violates the HTML spec. So let's stick with the notion of an empty ACTION. Same result, though.

How often have we all seen code along the lines of:

<form action="<cfoutput>#cgi.script_name#?#cgi.query_string#</cfoutput>" method="post">
...

or more involved:

<cfset action=CGI.SCRIPT_NAME>
<cfif CGI.QUERY_STRING NEQ "">
   <cfset action=action & "?" & xmlformat(CGI.QUERY_STRING)>
</cfif>
<form action="<cfoutput>#action#</cfoutput>" method="post">
...

All this could be replaced very simply with:

<form method="post" action="">
...

The form will post back to itself. I'll offer another post that shows a unique way to take advantage of this. In any case, I hope that this observation may help some folks.

(Update: I never got around to that other entry in 2007, but see a my reply to a comment below where someone asked for more info on the idea I had in mind.

Is this reliable?

Now, there are some who will argue that this is a violation of the HTTP HTML spec, and so it may be, but I've never found a browser in which it didn't work.

Again, a clarification over what I wrote originallyhere. As was refined in the comments below, it's a violation to have *no* ACTION, but it's perfectly legit according to the URI spec (section 4.2 at http://www.ietf.org/rfc/rfc2396.txt) to have an empty ACTION, which is interpreted as a "same-document reference. (Thanks, Christopher Bradford, for that info.) Given that, even the following cautions seem needless, but I'll leave them for any still concerned.

If you have any hesitation, because you have to support multiple browsers and you can't test all possibilities, I'll understand if you choose to pass on this. But certainly if you only need to support browsers you can test, then if it works as expected, enjoy.

If anyone reading this can offer where this is the case, I'd appreciate hearing it. If you want some simple code to test, try this:

<form method="post" action="">
   <input type="Submit">
</form>
<cfif cgi.request_method is "post">
   Posted to itself
</cfif>

If it shows the text within the IF, then it worked as expected.

What about query string info?

You may wonder about the earlier more involved examples that showed passing the query string, in case any had been passed to the form. No problem. This technique passes any query string along just fine. Try it yourself (add ?test=test to the form and view in the debugging info that it's still in the URL scope after submission.)

Like the UGTV site? Vote for it at CFDJ Awards

Note: This blog post is from 2006. Some content may be outdated--though not necessarily. Same with links and subsequent comments from myself or others. Corrections are welcome, in the comments. And I may revise the content as necessary.
My UGTV site has been nominated for "Best Web Site or Community" in CFDJ Reader's Choice Awards. If you've not yet voted, your vote would be appreciated. There are 8 other categories, and voting should take less than a minute.

The UGTV site is a directory of recorded UG presentations, now with 86 recordings from 65 presenters.

[....Continue Reading....]

CFFundamentals: Mimicking a form submission using CFHTTP

Note: This blog post is from 2006. Some content may be outdated--though not necessarily. Same with links and subsequent comments from myself or others. Corrections are welcome, in the comments. And I may revise the content as necessary.
While developers who've used CFML for a long time will regard some topics as old hat, we have to remember that there are folks who either have come along recently or simply never used some feature. This is one of those topics, and since I answered it on a list, I offer it here.

[....Continue Reading....]

Programmatically accessing allowed IP Addresses in Developer Edition (and understanding the limits)

Note: This blog post is from 2006. Some content may be outdated--though not necessarily. Same with links and subsequent comments from myself or others. Corrections are welcome, in the comments. And I may revise the content as necessary.
Have you ever needed to know programmatically what IP addresses, besides localhost, ARE allowed to access your Developer Edition of ColdFusion? I'll show you how here.

[....Continue Reading....]

Resources for Getting Started with CFEclipse

Note: This blog post is from 2006. Some content may be outdated--though not necessarily. Same with links and subsequent comments from myself or others. Corrections are welcome, in the comments. And I may revise the content as necessary.
As CFML developers contemplate (or make the move to) CFEclipse, which is a CFML plug-in for the open source Eclipse editor, they will naturally have questions. Does it support the features I want? What does it add? How easy is it to make the transition?

I think most developers will find that it does what they want (tag insight, tag help, code snippets, and more), and it will do still more than they may expect. Still, it may trip some up at first as they make a transition. Changing editors is always a challenging proposition, just because we become so used to our current editor. Still, more and more developers are making the switch, and you may want to learn more about it.

[....Continue Reading....]

Reloading CF web services programmatically, using the CF7 Admin API

Note: This blog post is from 2006. Some content may be outdated--though not necessarily. Same with links and subsequent comments from myself or others. Corrections are welcome, in the comments. And I may revise the content as necessary.
I'm surprised to not see much out there about how to reload or refresh CF's cached WSDL proxy for calling a web service, at least programmatically using the new CF 7 Admin API. Perhaps it's because people have been tripped up, or simply haven't explored it. Either way, I'd like to offer here the code you need, and also point out some tips and traps.

Update for CF8: As an update to this entry from 2006, which is focused on CF7, I'll note that there was yet another approach that was added in CF8. Both still work and have their own value. More on the CF8 feature in my later blog entry. Still, the feature added in CF7 is important to understand, too, so please read on.

[....Continue Reading....]

Corrected version of my Sept CFDJ article available online

Note: This blog post is from 2006. Some content may be outdated--though not necessarily. Same with links and subsequent comments from myself or others. Corrections are welcome, in the comments. And I may revise the content as necessary.
While it may seem old news, I want to point out that if you've received the print version of the September edition of the CFDJ (which came out in October), you may have seen my article on "FusionDebug Tips, Tricks, and Traps". Due to some glitches, the version printed was not the final, edited version I had offered.

I was able to arrange to get the corrected article posted in the electronic version of the article, free for you to read, on the CFDJ site. If you're interested in the topic and/or the article, please do check it out online.

Webcast: How to track views of your Breeze/Acrobat Connect recorded presentations

Note: This blog post is from 2006. Some content may be outdated--though not necessarily. Same with links and subsequent comments from myself or others. Corrections are welcome, in the comments. And I may revise the content as necessary.
I'm happy to present my first webcast, a short audio/video presentation showing a screen recording with narration of how to solve a problem. I plan to do many of these in the future.

[....Continue Reading....]

An alternative means of archiving your group's mailing list: Google Groups

Note: This blog post is from 2006. Some content may be outdated--though not necessarily. Same with links and subsequent comments from myself or others. Corrections are welcome, in the comments. And I may revise the content as necessary.
Did you know that a Google Group can be created solely to be an online repository/archive for another existing, traditional mailing list? I just learned this today.

[....Continue Reading....]

Alternative HTTP debugging proxies, for debugging

Note: This blog post is from 2006. Some content may be outdated--though not necessarily. Same with links and subsequent comments from myself or others. Corrections are welcome, in the comments. And I may revise the content as necessary.
I've previously mentioned the value of using HTTP debugging proxies, which help you observe the communications out of your browser and back, which can be especially helpful debugging problems with Ajax and Flex/Flash apps as well as general-purpose web apps. Though I've pointed out a couple of my favorites (Fiddler and Firebug) before, here is a larger list. "To each his own", as they say.

[....Continue Reading....]

More Entries

Copyright ©2025 Charlie Arehart
Carehart Logo
BlogCFC was created by Raymond Camden. This blog is running version 5.005.
(Want to validate the HTML in this page?)

Managed Hosting Services provided by
Managed Dedicated Hosting