Quickly set up CFPARAMs on a form processing page

I create lots of forms, and on the receiving pages for those forms it's always a good idea to set up CFPARAM fields, which automatically create the variable you're expecting to receive with a blank content, especially if you're using method="post" with your form. When using "post" if you haven't selected something like a checkbox, it doesn't send anything through for that checkbox, so if you try and call it with FORM.checkboxname on your process page you'll get an error.

But, typing in all the <CFPARAM NAME="FORM.whatever" DEFAULT=""> bits at the top of the file is very dull, especially if it's a long form. So now I use the code below to write the relevant code to the screen, and I cut and paste it back in to the file.

<CFOUTPUT>
<CFLOOP LIST="#FORM.FieldNames#" INDEX="ThisField">

&lt;CFPARAM NAME="FORM.#ThisField#" DEFAULT=""&gt;<br>

</CFLOOP>
</CFOUTPUT>

So the process is:

  1. Put the code above on the page that your form submits to
  2. Load the form in your browser, tick every checkbox and make sure any radio buttons have at least one option chosen
  3. Submit the form, on the processing page it will display a CFPARAM for all of the form fields
  4. Cut and paste the CFPARAMs in to the code on your processing page, replacing the code that wrote them

More code articles

Useful books
Cover of Mastering ColdFusion
Mastering ColdFusion MX
Amazon UK | USA
Cover of Programming ColdFusion MX
Programming ColdFusion MX
Amazon UK | USA
Cover of ColdFusion X Web Application Construction Kit
ColdFusion X Web Application Construction Kit
Amazon UK | USA

Paul Silver. November 2003


Silver Web Services Ltd

© 2017 Paul Silver