Sunday, October 18, 2009

Getting the values of the form with an array of input field name using Coldfusion

Well actually it is not really an array but I am trying to behave it like one. This is the code...............

//this is the sample form ............

<form method="post" action="coldfusion_handler.cfm">
    <input type="text" name="first_name_1" />
    <input type="text" name="first_name_2" />
    <input type="text" name="first_name_3" />
    <input type="submit" value="SUBMIT" />
</form>

// this would be your coldfusion page................

<cfif IsDefined('form.submit')>
  
    <cfloop index="x" from="1" to="3">
  
        <!--- set a string with with the value form.first_name_ and concatenate the index of your loop
        , note the form.first_name_ is the name of the input field from your form --->

        <cfset form_value="form.first_name_"&x>
      
        <!--- the coldfusion evaluate function takes a string argument and convert it into an object,
        in this case the value of the form_value is a string that contain something like this "form.first_name_1",
        then the Evaluate function calls that string and turns it into an object, in this case it behaves like this        

         #form.first_name_1#",  which as you can see calls the value of the form with the name .first_name_1 --->
        <cfoutput>#Evaluate(value)#</cfoutput>
    </cfloop>

</cfif>

well there it is. hope that helps.







No comments:

Post a Comment

Feeds

Sonic Run: Internet Search Engine javascript, coldfusion, programming, simple programming teckniques, css, html Webfeed (RSS/ATOM/RDF) submitted to http://www.feeds4all.nl Web Development & Design Blogs DigNow.net

Search Engine Optimization and SEO Tools
javascript, coldfusion, programming, simple programming teckniques, css, html