Skip to main content
December 23, 2010
Answered

form input question

  • December 23, 2010
  • 1 reply
  • 1129 views

Hi I have a cf template that I use to build new html pages with here at work. What I have so far works perfect. However, due to the way my employer lays his pages out, I am stumped at how to accomplish the next step in this page builder application.

Basically his pages are all the same static text heavy pages that follow the same design across literlayy thousands of product pages. Some pages however has a cross reference section or a "Equipment That Uses This Lamp" section. In these sections, each reference is laid out like a list. For example:

Acer

Vivitek

Westinghouse

and so on

Now my problem lies in how to use a form to insert text like this and still have it display as kind of a list. Its never a set number of items that might display here, so creating x number of form inputs would not work. Ideally I would like to have a way for the user(data entry) to type in multiple items in the one form, and have each different item display on a new line in succession. Not even sure this is possible, but any tips or suggestions would be greatly appreciated.

If you need more information let me know. You can also view exactly what I am talking about here Look at the bottom of the page and you will see a few short lists with bold text heading each list.

    This topic has been closed for replies.
    Correct answer ilssac

    Ok yes brandName would be something like GE or Philips. Those would be examples of the data she would be entering in the brandName form field. Then yes you are correct in that since the data I want to ultimately insert into my table is brandID which is an int datatype, then as I just tested, I get an error because the value of brandName is incorrect data type.

    So how would i go about easily converting SESSION.brandName into brandID without having to change my whole application? I dont want the user to be entering the brandID numbers, for one she doesnt know the unique auto increment numbers that corresponds to each brand name, and two brand names would be easier to recognize and see errors if they needed correction within the form.

    That was I guess why I thought I needed the where clause. to compare SESSION.brandName = brandID

    I know there should be an easy solution to this, but I and lost at the moment.


    SOLUTION ONE (the better one)

    Don't present the Brand Name as a text field, but make it a drop down select field populated with all the brands from the brands table.

    <select name="brandID"...>

          <cfoutput query="brandTableQuery">

               <option value="#brandID#">#brandName#</option>

          </cfoutput>

    </select>

    Now when the use picks a brand name, the field will be populated with the brand id and you would just use that field for the rest of your process.  (Doing queries of the brand table whenever you need to display the brand name.)

    SOLUTION TWO (the ugly one)

    You do a query on the brands table using the brand name the user intered into the text field.  The trouble her is that the user had to type the brand name EXACTLY as it is in the table, and goodness the confusion if there are brands with similar names!.

    You can combine the lookup into the insert query with a sub-query... but really SOLUTION ONE is the way to go!  So I'm not going to work up the syntax for this.

    1 reply

    ilssac
    Inspiring
    December 23, 2010

    Sure it is possible.

    If you care to get fancy you could create a javascript button that allows one to added new form input control(s) as needed.

    If you care to be simple, you could just use a text are form field that that user inputs a list into.

    You would then probably make use of ColdFusion list functions to process the data from either of these two options.

    http://livedocs.adobe.com/coldfusion/8/htmldocs/functions-pt0_13.html#1099435

    If you use the first option and you name the fields different names, then you would also want to be aware of array syntax notation for forms.

    <cfoutput>#form[field]#</cfoutput>

    Finally, I would really hope you would use related tables and normalize your database design to store the relationship between these items and the primary item.

    December 23, 2010

    Hi ilssac, thanks for the information. I will certainly look into these options. The form text area idea, I am assuming that the user enters her data, but then how each item gets placed on a new line in the final page is what I'm not sure about.

    Yes eventually I want all this form data to be inserted into my database. At the moment this site is static with NO database, but the parallel site I'm working on for the same product line is data driven, so as new pages are created, ideally the new products would be stored in the database.

    December 23, 2010

    ok so I was just doing some reading. I could have a text area where the user enteres data with each item

    separated by a delimiter(comma) by default. Then assign that text area as a variable with <cfset listItems=#textArea#> then I could loop through the data using:

    <ul>

    <cfloop index="listItems" list="#listItems#" delimiters=", ">
    <li><cfoutput>#listItems#</cfoutput></li>
    </ul>