Reply to topic
Handling spaces in a form field
cbsinet.com


Joined: 04 Oct 2004
Posts: 18
Location: Dunedin, FL
Reply with quote
I made a mail script in ColdFusion to mimmick sendmail.pl/formmail.pl to replace the perl scripts some of our clients used. The problem is that the form fields have spaces in some of the names and I can't seem to filter it out.

Any replies on this subject would be appreciated.

For now I just don't include that field but it's not a viable option. I either need to learn to support these or go change all the forms for over 100 clients. I never would've done the forms this way but I'm picking up where someone else left off. Not me! I didn't do it!

Thanks!
Josh
Forum Regular

Joined: 01 Apr 2004
Posts: 1047
Location: Felton, Delaware
Reply with quote
couldn't you just do a Replace?

Code:
Replace(#Field.Name#," ","_","All")
cbsinet.com


Joined: 04 Oct 2004
Posts: 18
Location: Dunedin, FL
Reply with quote
I'm not sure about that.

I use a CFLOOP with Form.FieldNames in the LIST arguement and I don't know how that code would fit in. The problem would come in the Evaluate function I use to try and get the value. It makes sense I can't get a value from a variable with a space in it.
steve
HostMySite Developer

Joined: 02 Mar 2004
Posts: 30
Reply with quote
In this case the Form variable is a structure so you can use the StructFind function to get the value of the form field.

It might look something like this:

Code:

<!--- this will display the form field name and its value --->
<cfloop list="#form.fieldnames#" index="tmp_name">
   #tmp_name#--#StructFind(form, "#tmp_name#")#   
</cfloop>




-Steve
loftboy
Forum Regular

Joined: 24 Jun 2004
Posts: 1129
Location: Colorado
Reply with quote
u should always trim formfields

#trim(form.field)#
kbrocx


Joined: 13 Oct 2004
Posts: 43
Location: Seattle
Reply with quote
Correct me if I'm wrong, but are you saying that the form filed names have spaces in them? As in "My Field"?
Trimming will only remove the spaces from the beginning and end of the variables value. It won't do anything for the varible name itself.
Whew, sorry you had to take that job over from someone!
If that is the case I'd just grit my teeth and change all those forms.
Leaving the spaces in a variable name is just not a good option.
Get real comfortable with Search and Replace!
bobclingan
Forum Regular

Joined: 16 Sep 2004
Posts: 272
Location: Abingdon, MD
Reply with quote
Recall that form fields are stored in a structure you can also reference the variables like this:

Code:
#form['my variable']#


Hope this helps!
byron
Forum Admin

Joined: 07 Mar 2004
Posts: 160
Location: Newark, DE, USA
Reply with quote
Even better, get real comfortable with RegEx find and replace Smile
loftboy
Forum Regular

Joined: 24 Jun 2004
Posts: 1129
Location: Colorado
Reply with quote
duh, i misread the ?

yeah u can always do some converting but thats pretty bad coding practice.

Im assuming u want to do this so u can use some java to validate the fields and u dont want it to look like

firstName is a required field

but u want it to look like

first Name is a required field

heres your solution, use a different extension, lol
or handwrite the variables for the java and properly name your fields
cbsinet.com


Joined: 04 Oct 2004
Posts: 18
Location: Dunedin, FL
Reply with quote
I solved the problem by referencing the FORM structure.

It's kind of neat to be able to name the form fields something stupid and still get the values. I personally don't name the fields with spaces but instead I might use an underscore and then replace it when viewing it is needed.

Other people made these forms for me to mail out. It was a good learning experience for me. Structures and me get along nicely now.

Thanks everyone for your help.
Handling spaces in a form field
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic