Two page method An easy way to submit forms in ColdFusion is to use two pages. First, you have a Form Page, where the user can input information and click a Submit button. The information is then sent to an Action Page, where the material sent from the form can be used to query a database for more information, to insert new information into the database, or perform other tasks. Combining the files into one A common way to perform both tasks on one page is to use a <CFIF IsDefined("form.submit")> tag to display what would be on the second page, provided the form has been submitted. This way, the Form Page and the Action Page are both coded in the same .cfm file. So, which way is best, and why?
I use both ways through out my site. I'm totally sure set on one being better than the other, but on advantage is... lets say you want to validate the information in the form. (of course you can use a client side script to do this) but lets say you want to use server side cf to validate. Well then by using the cfif IsDefined method you can display the errors ,if any, right on the same page so the user doesn't have to go back and reenter their information. They can just edit what is there. Now that I think about it though, I use cfif IsDefined on all my action pages anyway. I think the difference for me is that I have a message script that I wrote and instead of writing an action page for every form that is used to gather the "message" information, I just send all the messages to the same action page. I think the important things to consider are, 1) How much information are you gathering? 2)Are you going to use server side validation? (highly recommend) 3) Will multiple forms need to access the action page? 4) How complex is the action page going to be? The more complex it becomes i say separate them, because theres nothing fun about looking through 600 + lines of code to find one little problem. So whether a person is sending a new message or replying to a message I only have to use one action page to validate the information from the form.
I am a big advocate for MVC application frameworks such as Mach-II as a am a member of Team Mach-II. In the big 4 ColdFusion MVC frameworks, certainly including Mach-II, all requests are routed through index.cfm, so I send requests to events rather than individual cfm templates, but the same concepts generally apply. Usually I have a specific event for processing a post. For instance if I have a RegistrationForm event, I will have a submit.RegistrationForm event that will take the request The submit.Registration event would do whatever validation and persistance necessary, and then do a redirect to the destination event. This destination event could be either a "yay we're done!" page or it could send the user back to the form to fix errors. By sending to a page that does processing and then does an HTTP redirect (ie. cflocation) you alleviate the problem of someone hitting F5 and resubmitting their data.