form submission

Hi All,
Its been a while since I was writing any forms in CF and I have what will probably be a simple problem for you to help me solve.

I have a basic form

<cfform action="/qpi/loadfactor_form2.cfm" name="myform"  height="1800"  >

<table >
<cfoutput query="loadfactor">
<cfparam name="comments" default="&nbsp;"   >
<tr>
<td ><cfinput type="text" name="cons" value="#Container_cons_number#" readonly="yes" ></td>
<td>#Container_net_weight#</td>
<td ><cfselect query="cats" value="category" name="category" ></cfselect> </td>
<td ><cftextarea label="Comments" name="comments" required="yes"  cols="50"   value="#comments#" </cftextarea></td>
</tr>
</cfoutput>
<tr><td colspan="8" align="right"><cfinput type="submit" name="submit" value="Submit"></td></tr>
</table>
</cfform>

demo.JPG
This form is prepopulating some columns from a database and the user updates two corresponding columns with information.

I have an issue with the cftextarea field "comments".  I convert the list to an array on the second page.  I have inserted a space into the cftextarea so that the list always contains a value and does not fall out of sequence with the container number.  My concern is what if my users remove the space, thinking they are being helpful, I would update the wrong record.

So can I force the cftextarea list to always contain at least a space without showing it to the user.  So if the user does not type anything in that box can I insert a space ?
lokinsella1Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gdemariaCommented:
I think we should solve the problem without the space work-around.   How is having a space or not having a space going to update the wrong record in your database?   That sounds like a problem that should be fixed.

I don't really understand what the space is doing - what problem is it solving?

You mention you are converting "the list" to an array, but never mention where this list comes from.. are the users typing a list of things into the cftextarea?    

It seems like you have a problem which you are using this space to workaround, so let's talk about the problem and not the space?
0
_agx_Commented:
Agreed.  Looks like the bigger question is: "how to create a form for updating multiple records?"

I suspect the issue you're having is due to the fact that all of the form fields have the same name. So when the form is submitted you end up with one big CSV list of values for each field.  The problem with that is you need to use list functions to extract the individual values.  Unfortunately that's error prone.  Most CF list functions ignore empty elements. So if a user leaves a field blank, you'll end up with an uneven number of elements and your CF code will break The same will happen if a user enters a comma in one of the fields.

IMO, the better approach is use a counter number and create dynamic field names:  ie form.category1,form.category2, etc....



<cfform action="/qpi/loadfactor_form2.cfm" name="myform"  height="1800"  >
<cfoutput query="loadfactor">
    <cfinput type="text" name="cons#currentRow#" value="#Container_cons_number#" readonly="yes" ></td>
    <cfselect query="cats" value="category#currentRow#" name="category" ></cfselect>
    <cftextarea label="Comments" name="comments#currentRow#" required="yes"  cols="50"   value="#comments#" </cftextarea>
</cfoutput>

<input type="hidden" name="totalFields' value="#loadfactor.recordCount#">
<cfinput type="submit" name="submit" value="Submit">
</cfform>

Use a loop to extract the values and do whatever you need to do with them:


<cfloop from="1" to="#form.totalFields#" index="row">
         <!--- get field values --->
         <cfset category = FORM["category"&  row]>
         <cfset comments= FORM["comments"&  row]>
         <cfset cons = FORM["cons"&  row]>
         ....  do something with values ....

</cfloop>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gdemariaCommented:
Good catch agx, I didn't recognize it at as multiple record form, but that would certainly fit the issue.   I agree with the approach of adding a counter to the input form names as the best solution.

The asker also needs to keep in mind that the same situation will occur if someone enters a comma in the text or name fields.   That would also break the form.
0
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

_agx_Commented:
>> if someone enters a comma in the text or name fields.   That would also break the form.

Yep.  The same name field approach is very brittle.  At least up until CF9 :) I forgot that CF10  introduced a new feature. It let's you control whether "same-named-fields" are passed as CSV lists or arrays.  If you enable this setting your Application.cfc:

          this.sameFormFieldsAsArray = true;

.. all fields with the same name would be passed as arrays instead.
0
gdemariaCommented:
cool!  I didn't know about that..
0
lokinsella1Author Commented:
Many thanks for the feedback, I used this solution to solve the problem
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.