• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Database update with multiple form fields having the same name

Contributor ,
Jan 08, 2013 Jan 08, 2013

Copy link to clipboard

Copied

So I've made good progress on my CF photo album project, but now I've run into a snag.  Once I've uploaded a collection of photos and inserted them into my database, I bring up a page which is basically a table containing the thumbnail of each pic, some info about it, and the description of the pic.

The table is inside of a <form> tag, and the description is a <textarea> tag.  I have as many text areas as I have pics, so it can be any number (within reason).  I'd like to be able to type a description for each pic into each textarea rather than having to do them one at a time, then click the submit button to update my records.

Each textarea has the same name, so I had the idea to add a hidden form field that held the pic ID, then on the processing page I could maybe have a <cfloop>.  My problem is that I can't figure out how to associate each pic ID with the corresponding description, especially considering some of the descriptions might be blank.

Is there a proper way to do this?

Views

633

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jan 09, 2013 Jan 09, 2013

As you have probably figured out, giving all your textareas the same name means that when the form is submitted, you get one value which is a comma delimited list of each textarea's content.  If any commas are typed into the textarea you have a problem.

My preferred method is to include some sort of identifier as part of the form field name.  Since you have pic ids available, I'd use those.  That would give your textareas names like description_111, description_112, etc.

When the form is submitted

...

Votes

Translate

Translate
LEGEND ,
Jan 09, 2013 Jan 09, 2013

Copy link to clipboard

Copied

As you have probably figured out, giving all your textareas the same name means that when the form is submitted, you get one value which is a comma delimited list of each textarea's content.  If any commas are typed into the textarea you have a problem.

My preferred method is to include some sort of identifier as part of the form field name.  Since you have pic ids available, I'd use those.  That would give your textareas names like description_111, description_112, etc.

When the form is submitted, I loop through the form.fieldnames list.  If the first 12 characters are "description_111", I can remore 12 characters to get the id.  I can also get the contents of the textarea by using array notation.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 09, 2013 Jan 09, 2013

Copy link to clipboard

Copied

Dan Bracuk wrote:

As you have probably figured out, giving all your textareas the same name means that when the form is submitted, you get one value which is a comma delimited list of each textarea's content.  If any commas are typed into the textarea you have a problem.

Yes, I did notice the comma-delimited list of contents, except for the absence of the items I've left blank.  But I didn't even think about commas in the data.

I thought about using the ID number for each text area, then using "creative" applications of evaluate() and de() to get things to work, but that seemed a bit ham-fisted.

Appending something to the ID sounds promising.  I'll play with that when I get home tonight.

Thanks!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 09, 2013 Jan 09, 2013

Copy link to clipboard

Copied

LATEST

That worked really well Dan!  Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 09, 2013 Jan 09, 2013

Copy link to clipboard

Copied

I am not trying to answer your question directly, but I could make a recommendation that can help you learn even faster.  riaforge.org has loads of opensource projects several of them deal with problems you are trying to solve right now.  I find that learning how others solved similar problems can be very educational.  Even if you don't use their method for your current project it is info to tuck away into our brain database for later use.  So check out http://www.riaforge.org/index.cfm?event=page.search#photo  it has several photo album type projects and methodolgies you can use/borrow.

Tim

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 09, 2013 Jan 09, 2013

Copy link to clipboard

Copied

Thanks Tim, that's helpful.

Part of this project is to "do stuff myself" and I think most of the people on riaforge write code that's over my head, but it might not hurt to peek.  Plus, the more stuff I write, the better at it I seem to get, and it seems like I start to get more/better ideas on how to do things.  In fact, lately I've been going over some code I wrote for my office back in '06 and cringing, then re-writing it because I can now do it better.

The good thing about CF is that you can spend more time learning and writing new things and less time wracking your brain over some crazy syntax error.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation