Professional Web Applications Themes

Inserting Multiple Text Boxes? - Macromedia ColdFusion

I have a form that has 5 text boxes. <cfinput type='text' name='pack_location1'> <cfinput type='text' name='pack_location2'> <cfinput type='text' name='pack_location3'> etc etc etc A user might fill in all of the boxes or just 2. This assigns permissions for what locations users can see. On the insert I want to add these fields to the same table &amp; fields. Table: User_id: #form.user_id# Pack_location: #form.pack_location# How do I get an insert to loop through and insert whatever the user enters in the form? I know i can just do it manually but i'd like to loop it....

  1. #1

    Default Inserting Multiple Text Boxes?

    I have a form that has 5 text boxes. <cfinput type='text'
    name='pack_location1'> <cfinput type='text' name='pack_location2'> <cfinput
    type='text' name='pack_location3'> etc etc etc A user might fill in all of the
    boxes or just 2. This assigns permissions for what locations users can see.
    On the insert I want to add these fields to the same table &amp; fields.
    Table: User_id: #form.user_id# Pack_location: #form.pack_location# How do I
    get an insert to loop through and insert whatever the user enters in the form?
    I know i can just do it manually but i'd like to loop it.

    craig_uk Guest

  2. #2

    Default Re: Inserting Multiple Text Boxes?

    You can adjust the loop count as needed depending on the number of text
    fields. Try:



    <cfloop index="i" from="1" to="5">
    <cfif Len(Trim(Evaluate("form.pack_location" & i)))>
    This field is defined...do something in here...
    </cfif>
    </cfloop>

    blewis Guest

  3. #3

    Default Re: Inserting Multiple Text Boxes?

    Thanks for the quick reply. I have changed the code to this. <cfloop
    index='i' from='1' to='8'> <cfif Len(Trim(Evaluate('form.pack_location'
    &amp; i)))> <CFQUERY name='insert_pack' datasource='tns'> INSERT INTO
    pack_data_tbl (user_id, pack_location ) VALUES
    ('#form.user_id#', '#form.pack_location#' ) </CFQUERY> </cfif>
    </cfloop> I'm going wrong somewhere as I get an error when the insert takes
    place. Element PACK_LOCATION is undefined in FORM.

    craig_uk Guest

  4. #4

    Default Re: Inserting Multiple Text Boxes?

    This error is being produced because form.pack_location does not exist,
    form.pack_location1, 2, 3, etc do. You need to use Evaluate() like I did to
    build the dynamic variable.

    In your VALUES section of the query, change '#form.pack_location#' to
    '#Evaluate("form.pack_location" & i)#'

    Bryan

    blewis Guest

  5. #5

    Default Re: Inserting Multiple Text Boxes?

    I have now changed it to; <cfloop index='i' from='1' to='7'> <cfif
    Len(Trim(Evaluate('form.pack_location' &amp; i)))> <CFQUERY
    name='insert_pack' datasource='tns'> INSERT INTO pack_data_tbl
    (user_id, pack_location ) VALUES ('#form.user_id#',
    '#Evaluate('form.pack_location' &amp; i)#' ) </CFQUERY> </cfif>
    </cfloop> When I submit I get 'page cannot be displayed internal server error'
    When I check the DB it has entered the first Pack_location then seems to fall
    over.

    craig_uk Guest

  6. #6

    Default Re: Inserting Multiple Text Boxes?

    Since it do not report a specific error, I am not sure what's up. I would do
    some basic debugging. So that I can see what is going on, replace the CFQUERY
    tags with CFOUTOUT and put a CFABORT after the loop so that processing will
    stop. Then cut-and-paste the rendered output here so we can see what the
    queries would look like if they were actually being run.

    I assume that given you have a to="7" that you have 7 text fields on the form?

    Bryan


    blewis Guest

  7. #7

    Default Re: Inserting Multiple Text Boxes?

    All is well now, I had not saved and refreshed the form that passes the data, doh!
    craig_uk Guest

  8. #8

    Default Re: Inserting Multiple Text Boxes?


    ok, glad to hear it works.
    blewis Guest

Similar Threads

  1. Inserting Check Boxes
    By kingjes in forum Coldfusion - Getting Started
    Replies: 4
    Last Post: August 29th, 08:43 PM
  2. form: single line -- multiple text boxes -- one typing field - how?
    By confused99@adobeforums.com in forum Adobe Acrobat Windows
    Replies: 13
    Last Post: April 28th, 02:50 AM
  3. Hyperlink text issue, two text boxes, one disfuntional
    By WickedSense webforumsuser@macromedia.com in forum Macromedia Director Basics
    Replies: 0
    Last Post: November 7th, 05:33 PM
  4. seperating columns in a text box into multiple text boxes?
    By Greg Doudna in forum Microsoft Access
    Replies: 1
    Last Post: July 9th, 08:12 PM
  5. Multiple combo boxes
    By heather in forum Microsoft Access
    Replies: 5
    Last Post: July 7th, 11:18 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139