Automatic Form Generator

Every time you start a new application in cold fusion, you need some sort of a form which mostly contain elements like ?text, hidden, password, submit?
It could boring if you use the CF editor, to pick ?cfform? fill its attributes, then pick ?cfinputs? one by one, fill out those attributes?.one by one, then change tabs and pick the ?submit? button ?so on and so forth. Even if you code in a note pad, it might get lengthy to code individual element.
Wouldn?t it be nicer to code all these elements at once, then just copy the code and paste it in your editor ?
The following shows u how ?
This is not a tutorial as such, more like an application that you can put in a directory.

Generally we know a particular Sign-In form will have 3 fields username, password and a submit button.
The point is, before you build a form page, you almost always know how many fields you need

So you start here by saying to your self?.?well? lets see, I need 5 fields on my form?
Step1.cfm

<cfform action="step2.cfm" method="POST" enablecab="Yes">
    <table>
        <caption><h3 style="font-family:arial;background:efefef;">Step 1</h3></caption>
        <tr>
            <td>
Number Of Form-Fields :</td>
            <td>

                <select name="field_nos" style="width:60px; font-family:arial;background:efefef;">
                <!--- I have just restricted this example for 30 form fields. You can increase
                        that limit by increasing ?to? number in your loop --- >


                <cfloop index="i" from="1" to="30" step="1">
                    <cfoutput>

                        <option value="#i#">#i#</option>
                    </cfoutput>
                </cfloop>


                </select>
            </td>
            <td>

                <font size="-1">Choose between 1 & 30 !</font>
            </td>
        </tr>
        <tr>
            <td colspan="3" align="center">
<input type="submit" value="Go To Step - 2"></td>
        </tr>
    </table>

</cfform>

step2.cfm
So you have come to phase 2 or step 2, where you can fill out many attributes of each of the fields in your form.

Since all ?<cfinput? tags need a ?<cfform? tag to get parsed?begin by filling out FORM DETAILS?.

<cfform action="step3.cfm" method="POST" enablecab="Yes" name="step2">
    <table>
        <tr>
            <td colspan=
"3" style="font-family:arial;font-weight:bold;background:efefef;">
              
 FORM DETAILS !
               
<pre>
                   
Form Name: <cfinput type="Text" name="form_name" required="yes">
                   
Form Action:<cfinput type="Text" name="form_action" required="yes">
                   
Method: <cfselect name="Form_Method" required="Yes">
                                   
<option value="Post">Post</option>
                                   
<option value="Get">Get</option>
                                </cfselect>

                   
Enablecab: <cfselect name="enable_cab" required="Yes">
                                       
<option value="Yes">Yes</option>
                                       
<option value="No">No</option>
                                   
</cfselect>
               
</pre>
            </td>
        </tr>
       
<!--- remember on the last page we filled in how many fields we need in our form ??this is why. ?..so now u can generate as many fields. This loop should accomplish that --- >

       
<cfloop index="gen_frm" from="1" to="#form.field_nos#">
        <tr>
            <td style=
"font-family:arial;font-weight:bold;background:efefef;">
             
  FIELD <cfoutput>#gen_frm#</cfoutput> CAPTION:
            </td>
            <td>
               
<cfinput type="Text" name="Caption#gen_frm#">
            </td>
        </tr>
        <tr>
            <td>
FIELD TYPE:</td>
            <td>

           
<!--- cold fusion also requires that each name attribute in a single form, be unique.
                    Our loops serves that purpose too, by appending sort of an id number to name a ?<cfinput name=? tag --- >

            <!--- here are just a few types of elements in a form. Oh yes? and if you need a Yes/No radio button, make sure
                    you count it twice ! one for the ?yes? and one for the ?no?--- >


           
<cfselect name="frm_type#gen_frm#" required="Yes">
               
<option value="text">Text</option>
                <option value=
"Submit">Submit</option>
                <option value=
"hidden">Hidden</option>
                <option value=
"password">Password</option>
                <option value=
"radio">Radio</option>
                <option value=
"checkbox">CheckBox</option>
            </cfselect>

            </td>
        </tr>
        <tr>
            <td>
FIELD NAME:</td>
            <td>
<cfinput type="Text" name="frm_name#gen_frm#" message="Form Name in field-#gen_frm# is required !" required="Yes"></td>
            <td></td>
           
<!--- in the ?message? section above is so designed that if you leave this field blank, the pop-up should tell you exactly which field you left blank --- >
        </tr>
        <tr>
            <td>
FIELD VALUE:</td>
            <td>
<cfinput type="Text" name="frm_value#gen_frm#"></td>
            <td></td>
        </tr>
        <tr>
            <td>
FIELD SIZE:</td>
            <td>
<cfinput type="Text" name="frm_size#gen_frm#"></td>
            <td></td>
        </tr>
        <tr>
            <td>
FIELD MAX LENGTH:</td>
            <td>
<cfinput type="Text" name="frm_maxln#gen_frm#"></td>
            <td></td>
        </tr>
        <tr>
            <td>
FIELD REQUIRED:</td>
            <td>
               
<cfselect name="frm_req#gen_frm#" required="Yes">
                   
<option value="Yes">Yes</option>
                    <option value=
"No">No</option>
                </cfselect>

            </td>
            <td></td>
        </tr>
        <tr>
            <td>
FIELD MESSAGE:</td>
            <td>
<cfinput type="Text" name="frm_message#gen_frm#"></td>
            <td style=
"font-size:9pt;background:efefef;">Add custom message if this field is required !</td>
        </tr>
        <tr>
            <td>
FIELD TAB INDEX:</td>
            <td>
<cfinput type="Text" name="frm_tabind#gen_frm#"></td>
            <td style=
"font-size:9pt;background:efefef;"></td>
        </tr>
        <tr>
            <td colspan=
"3"><hr style=";color:black;border-width:thin;border-style:dashed;"></td>
        </tr>

       
</cfloop>

        <tr>
           
<input type="hidden" name="loop_times" value="<cfoutput>#field_nos#</cfoutput>">

            <td colspan=
"3" align="center"><input type="submit" value="Create Form"></td>
        </tr>

    </table>

</cfform>

step3.cfm

This page will display your form ?Form Test Section?, as well as spit-out the code in the ?code section? Try it out !!!

<!--- This is what shows you the form. If you have made a particular field ?required? and
on the test form section, you try to submit this form with an empty required field, then the CF should pop up a window with your message. If you had not specified a message, then a default message should pop up --- >


<h2>
FORM TEST SECTION</h2>
<cfform action="#form_name#" method="#form_method#" enablecab="#enable_cab#" name="#form_name#">
    <table>

        <cfloop index="gen_frm" from="1" to="#loop_times#">
        <tr>
            <cfset Caption="Caption#gen_frm#">
            <cfset frm_type=
"frm_type#gen_frm#">
            <cfset frm_name=
"frm_name#gen_frm#">
            <cfset frm_value=
"frm_value#gen_frm#">
            <cfset frm_size=
"frm_size#gen_frm#">
            <cfset frm_maxln=
"frm_maxln#gen_frm#">
            <cfset frm_req=
"frm_req#gen_frm#">
            <cfset frm_message=
"frm_message#gen_frm#">
            <cfset frm_tabind=
"frm_tabind#gen_frm#">
           
            <cfset Caption=
"#Evaluate(Caption)#">
            <cfset frm_type=
"#evaluate(frm_type)#">
            <cfset frm_name=
"#evaluate(frm_name)#">
            <cfset frm_value=
"#evaluate(frm_value)#">
            <cfset frm_size=
"#evaluate(frm_size)#">
            <cfset frm_maxln=
"#evaluate(frm_maxln)#">
            <cfset frm_req=
"#evaluate(frm_req)#">
            <cfset frm_message=
"#evaluate(frm_message)#">
            <cfset frm_tabind=
"#evaluate(frm_tabind)#">
           
            <cfif frm_type neq
"Submit">
                <cfif frm_maxln
eq ''>
                    <cfset frm_maxln=
255>
                </cfif>

                <cfif frm_size
eq ''>
                    <cfset frm_size=
25>
                </cfif>

                <cfif frm_message
eq ''>
                    <cfset frm_message=
"#caption# is required !">
                </cfif>


                <td>
                    <cfoutput>#Ucase(Caption)#</cfoutput>
                </td>
                <td>

                    <cfinput type=

All ColdFusion Tutorials By Author: Anang A Phatak
  • A DataSet just like VB.Net
    This tutorial shows you how to create a "dataset" just like the one in VB.Net In VB.Net you would create a dataset with "edit" button in an extra column. Once you click "edit", you get an option to "update", "delete" or "cancel edit mode" This is just like a cfgrid tag. Although a cfgrid tag lets you bulk insert, bulk update or bulk delete, the dataset object does it one by one. But cfgrid is slower, and may give users Java errors, depending on their browser settings.
    Author: Anang A Phatak
    Views: 15,191
    Posted Date: Wednesday, November 17, 2004
  • A Mp3 Streaming Server
    This is a small application that shows you how to create an MP3 streaming server.
    Author: Anang A Phatak
    Views: 12,469
    Posted Date: Monday, November 8, 2004
  • A plot to plot a line
    I had no work one day due to a worm attack on our servers, thus a plot to plot a line on a graph was hatched in my empty mind. These files show you, how to plot a line using no database, no java, no long wait times for aplet loading, just 3 tools, Loop, table and text.
    Author: Anang A Phatak
    Views: 8,220
    Posted Date: Thursday, May 6, 2004
  • A random password generator
    RANDOM PASSWORD GENERATOR SCRIPT ! I know there is a random password tutorial here already. This is just another way to do the same. I think this is a little easier to understand. Refresh it to generate a new password string everytime !
    Author: Anang A Phatak
    Views: 9,858
    Posted Date: Monday, May 24, 2004
  • Advanced Calculator
    I have posted a "Basic Calculator" tutorial here. That was more like a representation of how you would calculate with a paper and a pencil. You provide INPUT A then a MATHEMATICAL OPERATION like a "+" or a "-" and then an INPUT B. This is more a represntation of how you would use a regular hand-held calculator complete with buttons for NUMBERS, OPERATIONS and CLEAR TEXT.
    Author: Anang A Phatak
    Views: 9,026
    Posted Date: Friday, June 18, 2004
  • Automatic Form Generator
    This is not a tutorial as such, more like an application that you can put in a directory. It could boring if you use the CF editor, to pick "cfform" fill its attributes, then pick "cfinputs" one by one. fill out those attributes... one by one, then change tabs and pick the "submit" button... so on and so forth. Even if you code in a note pad, it might get lengthy to code individual element. Wouldn't it be nicer to code all these elements at once, then just copy the code and paste it in your editor?
    Author: Anang A Phatak
    Views: 9,547
    Posted Date: Thursday, May 20, 2004
  • Automatically Query To CFM
    This is a custom tag application. The cf_QueryRender custom tag takes your query arguments and gives you a final page table and all...
    Author: Anang A Phatak
    Views: 11,513
    Posted Date: Friday, October 29, 2004
  • Breaking down your query results into pages (Paging Tutorial)
    I havent come across a "paging" tutorial on this site. I know there are JavaScripts available that help you achieve this, and the DataSet object in VB.Net comes with paging. All you do is "enable paging". But how do you do it in ColdFusion ?
    Author: Anang A Phatak
    Views: 15,204
    Posted Date: Tuesday, November 16, 2004
  • Breaking down your query results into pages (Paging Tutorial) Part-II
    This is an extension to my last tutorial "Breaking down your query results into pages (Paging Tutorial)" which is posted here on www.easycfm.com In the last tutorial, you could retrieve a dataset with a , then use a technique to seperate the results over several pages. It simply ; - took the total "recordCount" - divided that with the "number of records per page" - then displayed the number of pages at the bottom of the table. This is a little more sophisticated than that. Read on...
    Author: Anang A Phatak
    Views: 7,894
    Posted Date: Wednesday, January 11, 2006
  • ColdFusion MX 6.1 Installation on Linux (Ubuntu -- Hoary Hedgehog)
    I have tried hoards of websites on how to install coldfusion on Fedora Core 3 with apache webserver. For some reason the connectors always failed. I had "Ubuntu" on my laptop, basically because "acpi" suspend/hibernate actually works. I decided I might try to install CF there to find out what was going wrong. Surprisingly everything worked like a charm. Make sure you use "apt-get install apache2" before you try this. BEST OF LUCK ....
    Author: Anang A Phatak
    Views: 9,890
    Posted Date: Tuesday, May 10, 2005
  • Dynamic textbox and progress bar for your pages
    The principle of this tutorial is similar to "Dynamic time and date for your pages" tutorial. Except that this one generates messages, and that one updated time. Read on, you will get the hang of it....
    Author: Anang A Phatak
    Views: 11,922
    Posted Date: Thursday, May 19, 2005
  • Dynamic time and date for your pages
    Have you seen the "www.EasyCFM" page closely? On the main page, top right, there is a place for time, and top left a place for day-date. Ever wonder how Pablo does it ? This is not a ColdFusion tutorial. Its JavaScript.
    Author: Anang A Phatak
    Views: 9,845
    Posted Date: Wednesday, January 5, 2005
  • Getting ColdFusion Studio for Linux
    I like using HomeSite+ for windows, and I am getting used to Dreamweaver Mx. But I still need something just as good for Linux. For some reason, I couldnt get "wine and Dreamweaver Mx" to work. So I "Googled" a bit and stumbled upon Eclipse and cfEclipse. Here is how to set it up.
    Author: Anang A Phatak
    Views: 10,900
    Posted Date: Wednesday, May 25, 2005