Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

extra commas

Status
Not open for further replies.

harrymossman

Technical User
Sep 5, 2002
255
0
0
US
We have a form that allows people to create a letter to themselves to accompany some information they have selected. It has started inserting extra commas in front of fields. This does not happen when I test the form on my computer, just on the remote server.

Harry

Code:
<!--- Exerpt from form page --->
<cfloop collection="#FORM#" item="whichField">
<cfoutput>
<input type="hidden" name="#whichField#" value="#FORM[whichField]#">
</cfoutput>
</cfloop>
<p>Your Name: 
<cfoutput>
<input type="text" name="name" value="#FORM.name#" size="75">
</cfoutput>
</p>

<!--- Exerpt from action page --->
<cfoutput>#Form.name#<br>
 
You are entering the "name" field twice on your form. Once in your loop from the previous form submission and also once by itself (highlighted below)

Code:
<!--- Exerpt from form page --->
<cfloop collection="#FORM#" item="whichField">
<cfoutput>
[COLOR=black yellow]<input type="hidden" name="#whichField#" value="#FORM[whichField]#">[/color]
</cfoutput>
</cfloop>
<p>Your Name: 
<cfoutput>
[COLOR=black yellow]<<input type="text" name="name" value="#FORM.name#" size="75">[/color]
</cfoutput>
</p>

If the "name" field was "Fred" on the previous form and "John" on this form, on your action page the value of #form.name# is "Fred,John" -- If "name" was previously blank, and is "John" now, #form.name# could quite conceivably be ",John" <-- There's your extra comma.

Joe
 
Thanks Joe, but I'm not following you. The highlighted code is all on one form.

The first <input etc> collects what is entered in various <input type="text" etc.> fields throughout. The code was given to me by someone in this forum. It works just fine on my computer.
 
Here's what it looks to me like you are trying to do:

PAGE A: A form that submits to page B, and includes a field called "name"

PAGE B: Another form, which includes the data submitted from the form on page A, plus another field called "name"

PAGE C: the action page, where the from from page B is processed.

If that is the case, then you are placing two fields called "name" in your form on page B. One from the loop that repeats your previous form data, and another one for entry. try changing your loop to look like this and see if it works:
Code:
<cfloop collection="#FORM#" item="whichField">
 <cfoutput>
  <cfif whichfield NEQ "name">
   <input type="hidden" name="#whichField#" value="#FORM[whichField]#">
  </cfif>
 </cfoutput>
</cfloop>

Joe
 
No page B. Page A collects name, address, etc. and submits them to the action page.
 
if you only have one form why do you have
<cfoutput>
<input type="hidden" name="#whichField#" value="#FORM[whichField]#">
</cfoutput>

what that does is takes the form variables and values and creates hidden fields with them to pass to yet another form as a form variable.

maybe it would be best to see all of your code.

Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
Also, why do you have...

<input type="text" name="name" value="#FORM.name#" size="75">

...the "#form.name#" variable indicates that you are filling this field with the value of the "name" field from a form that was submitted to this page.
 
Ok, here's the code:

Form Page
Code:
<cfform action="auto_letter_draft.cfm" method="POST" enablecab="Yes">

<cfloop collection="#FORM#" item="whichField">
<cfoutput>
<input type="hidden" name="#whichField#" value="#FORM[whichField]#">
</cfoutput>
</cfloop>

<p class="top0">Your Name:<br>  
<cfoutput>
<input type="text" name="name" value="#FORM.name#" size="75">
</cfoutput>  </p>
<p>Salutation: (How would you like for us to address you? E.g. Ms. Smith)<br>
<cfoutput><input type="text" name="salute" value="#FORM.salute#" size="75"></cfoutput></p>
<p>Your Organization: (if applicable)<br>
<cfoutput>
<input type="text" name="org" value="#FORM.org#" size="75">
</cfoutput></p>
<p>Your Street Address:<br>
<cfoutput>
<input type="text" name="st" value="#FORM.st#" size="75">
</cfoutput><br> 
<cfoutput>
<input type="text" name="st2" value="#FORM.st2#" size="75">
</cfoutput></p>
<p>City:<br>
<cfoutput>
<input type="text" name="city" value="#FORM.city#" size="75">
</cfoutput></p>
<p><cfoutput>State:<br>
<input type="text" name="state" value="#FORM.state#" size="2">
</cfoutput></p>
<p>Zip code:<br> 
<cfoutput>
<input type="text" name="zip" value="#FORM.zip#" size="10">
</cfoutput>  </p>
<p>Country:<br>
<cfoutput>
<input type="Text" name="country" value="#FORM.country#" size="75">
</cfoutput></p>
<p>Project Name or Description (if applicable):<br>
<cfoutput>
<input type="text"
name="proj"
value="#FORM.proj#"
size="75"
maxlength="256">
</cfoutput></p>
<p>Location of the Project:<br>
<cfoutput>
<input type="text" name="loc" value="#FORM.loc#" size="75">
</cfoutput>
</p>
       
<input type="reset" value="Reset">
<input type="submit" name="submit" value="Get letter ->">
</p>
</cfform>

Action Page (letter)
Code:
!--- Address Block --->
<p>
<cfoutput>#Form.name#<br>

<cfif #form.org# is not "">
#form.org#<br>
</cfif>

<cfif #form.st# is not "">
#form.st#<br>
</cfif>

<cfif #form.st2# is not "">
#form.st2#<br>
</cfif>

<cfif #form.city# is not "">
#form.city#, #form.state# #form.zip#
</cfif>
</cfoutput></p>

<p>
<cfif proj is "">
Subject: Not specified
<cfelse>
<cfoutput>Subject: Species List for #form.proj#</cfoutput>
</cfif>

</p>

<!--- Salutation --->
<p>Dear:
<cfif salute is "">
Interested party
<cfelse>
<cfoutput>#form.salute#</cfoutput>
</cfif>
</p>
 
Also, why do you have...

<input type="text" name="name" value="#FORM.name#" size="75">

...the "#form.name#" variable indicates that you are filling this field with the value of the "name" field from a form that was submitted to this page.

Can't answer that. I'm pretty much a novice. As I mentioned, the code was suggested by someone in this forum and when I tried it, it worked.

Harry
 
There must be a form posting data to your form page, otherwise you would be getting a bunch of error messages on your #form...# variables. The #form...# scope refers to variables that were passed to the page using a POSTed form.

Your loop, (<cfloop collection="#FORM#" item="whichField">...</cfloop>) creates hidden form fields matching the ones that were posted to this page. Then, you add additional fields, which seem to have the same names as those in the posted form, giving you duplicate field names in this form.

When field names are duplicated in a posted form, they appear as a comma-separated list on the action page. For instance,
<input type="hidden" name="uname" value="John">
<input type="text" name="uname" value="Mike">
will give you a variable on the next page called #form.uname# with a value of "John,Mike"

Try this code instead. It will emilinate your duplicates:

Code:
<cfset doneflds = "">
<cfform action="auto_letter_draft.cfm" method="POST" enablecab="Yes">
<cfoutput>
<p class="top0">
 Your Name:<br>
 <input type="text" name="name" value="#FORM.name#" size="75">
 <cfset doneflds = listappend(doneflds,"name")>
</p>
<p>
 Salutation: (How would you like for us to address you? E.g. Ms. Smith)<br>
 <input type="text" name="salute" value="#FORM.salute#" size="75">
 <cfset doneflds = listappend(doneflds,"salute")>
</p>
<p>
 Your Organization: (if applicable)<br>
 <input type="text" name="org" value="#FORM.org#" size="75">
 <cfset doneflds = listappend(doneflds,"org")>
</p>
<p>
 Your Street Address:<br>
 <input type="text" name="st" value="#FORM.st#" size="75"><br> 
 <input type="text" name="st2" value="#FORM.st2#" size="75">
 <cfset doneflds = listappend(doneflds,"st,st2")>
</p>
<p>
 City:<br>
 <input type="text" name="city" value="#FORM.city#" size="75">
 <cfset doneflds = listappend(doneflds,"city")>
</p>
<p>
 State:<br>
 <input type="text" name="state" value="#FORM.state#" size="2">
 <cfset doneflds = listappend(doneflds,"state")>
</p>
<p>
 Zip code:<br> 
 <input type="text" name="zip" value="#FORM.zip#" size="10">
 <cfset doneflds = listappend(doneflds,"zip")>
</p>
<p>
 Country:<br>
 <input type="Text" name="country" value="#FORM.country#" size="75">
 <cfset doneflds = listappend(doneflds,"country")>
</p>
<p>
 Project Name or Description (if applicable):<br>
 <input type="text" name="proj" value="#FORM.proj#" size="75" maxlength="256">
 <cfset doneflds = listappend(doneflds,"proj")>
</p>
<p>
 Location of the Project:<br>
 <input type="text" name="loc" value="#FORM.loc#" size="75">
 <cfset doneflds = listappend(doneflds,"loc")>
</p>
<p>
 <input type="reset" value="Reset">
 <input type="submit" name="submit" value="Get letter ->">
 <cfset doneflds = listappend(doneflds,"submit")>
</p>

<cfloop collection="#FORM#" item="whichField">
 <cfif listfindnocase(doneflds,whichfield) EQ 0>
  <input type="hidden" name="#whichField#" value="#FORM[whichField]#">
 </cfif>
</cfloop>

</cfoutput>
</cfform>
 
There must be a form posting data to your form page, otherwise you would be getting a bunch of error messages on your #form...# variables. The #form...# scope refers to variables that were passed to the page using a POSTed form.

There is a previous form but it doesn't include any of these fields. The whole sequence is that on Form A the user selects what they want on a list:

Code:
<!--- Get list of quads to populate select box. --->
<cfquery name="ListQuads" datasource="#dsn#">
SELECT      DWRCODE, QUADNAME
FROM        QuadList
</cfquery>
<!--- Get list of counties to populate select box. --->
<cfquery name="ListCo" datasource="#dsn#">
SELECT      CoIndex, CoName, Region
FROM        CoName
ORDER BY    CoName
</cfquery>

<cfform action="auto_list.cfm" method="POST" enablecab="Yes">
  <!--- Select counties --->
  <cfselect name="coIndex"
          size="20"
          required="No"
          multiple>
  <cfoutput query="listCo">
      <option value="#coIndex#">&nbsp;#CoName# #Region#
  </cfoutput></cfselect>&nbsp;&nbsp;&nbsp;
  <!--- Select quads --->
  <cfselect name="Quads" 
  size="20" 
  multiple>
    <cfoutput query="ListQuads">
    <option value="#DWRCODE#">#DWRCODE# &nbsp;&nbsp;#ucase(QUADNAME)#
    </cfoutput>
  </cfselect>
  <p class="top5 bottom10">(You can select more than one item by holding down your Shift 
  and/or Ctrl key)</p>

  <input type="submit" name="submit" value="Make Species List">
  <input type="reset" value="Reset">  
</cfform>

That produces the list on Form B. On that form, there is a button to bring up Form C which they fill out to get a letter. Form C is the form I am inquring about.

Code:
<!---                   MAKE SPECIES LIST LETTER                     --->
<form action="auto_letter_form.cfm" method="POST" class=heightzero">
  <cfloop collection="#FORM#" item="whichField">
       <cfoutput>
         <input type="hidden" name="#whichField#" value="#FORM[whichField]#">
       </cfoutput>
  </cfloop>

    <cfset DocNumber = "#DateFormat(now(), 'yy')##DateFormat(now(), 'mm')##DateFormat(now(), 'dd')##TimeFormat(now(),'hh')##TimeFormat(now(),'mm')##TimeFormat(now(),'ss')#">
    <cfoutput>
    <input type="hidden" name="DocNumber" value="#DocNumber#">
    </cfoutput>    
    <input type="submit" name="submit" value="Make Official Letter ->">
</form>

When Form C comes up, the user fills in name, address, etc. fields and submits. This brings up Form D, which is a draft letter. (This letter has the extra commas.) If this letter is ok, the user submits to get the final action page, the official letter (which also has the extra commas.)
 
Take this field for instance:
<input type="text" name="state" value="#FORM.state#" size="2">

If the form that posted to this page does not have a field called "state", this should throw an error. If it is not throwing an error and you are certain that the posted form does not have that field, then I don't know what's going on.

Have you checked the debugging information to follow the progress of your form variables as you proceed through the pages?

Joe
 
Have you checked the debugging information to follow the progress of your form variables as you proceed through the pages?

No, because there are no bugs when I test on my computer. Just on the remote server.
 
If the code is the same on your machine and the remote server, the debugging information should be more or less the same. If the commas are not there on your machine, I imagine it's a CF version difference that interprets duplicate form fields differently. So, you should be able to see the form fields being passed at each stage in the debugging on your local machine.

Make sure you have debugging turned on, and your IP in the debugging IPs, then start at the beginning of your form chain and as you go through, scroll to the bottom of each screen to see what your form variables are. I think you will be able to find where the duplicates are coming from this way.

Joe
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top