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.
<CFLOOP LIST="#FORM.FieldNames#" INDEX="ThisField">
<CFPARAM NAME="FORM.#ThisField#" DEFAULT=""><br>
So the process is:
- Put the code above on the page that your form submits to
- Load the form in your browser, tick every checkbox and make sure any radio buttons have at least one option chosen
- Submit the form, on the processing page it will display a CFPARAM for all of the form fields
- Cut and paste the CFPARAMs in to the code on your processing page, replacing the code that wrote them
Paul Silver. November 2003