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!

Trimming Form Fields

Status
Not open for further replies.

MrSki

Programmer
Dec 13, 2000
66
0
0
US
I have a page where I am trying to trim the form data entered on the previous page to clean things up and rid any extra spaces. This is the script that is on the page and it is tossing an error that I am unable to resolve. Any ideas?

<cfscript>
// Trim all form fields
for (i = 1; i lte listLen(form.fieldNames); i = i + 1) {
evaluate("form.#i# = trim(form.#i#)");
}
</cfscript>



Mitch Duszynski
Web Developer
Human Kinetics
PO Box 5076, Champaign, IL 61825
Tel: 217-351-5076 x2474 | Fax: 217-351-2674
mitchd@hkusa.com |
 
You could just use CF's built in Trim() function. If you're inserting data into the database, just trim the values in the query:
Code:
<cfquery name="whatever" datasource="whatever">
Insert Into TableA(Column1, Column2)
Values(#Trim(Form.Field1)#, #Trim(Form.Field2)#
</cfquery>



Hope This Helps!

Ecobb

&quot;My work is a game, a very serious game.&quot; - M.C. Escher
 
Try this...

Code:
<cfscript>
  // Trim all form fields
  for (i = 1; i lte listLen(form.fieldNames); i = i + 1) {
    form.#i# = trim(evaluate("form.#i#"));
    }
</cfscript>

or maybe this..

Code:
<cfscript>
  // Trim all form fields
  for (i = 1; i lte listLen(form.fieldNames); i = i + 1) {
    "form.#i#" = trim(evaluate("form.#i#"));
    }
</cfscript>

For faster processing though.. try this, I think it should work..

Code:
<cfscript>
  // Trim all form fields
  for (i = 1; i lte listLen(form.fieldNames); i = i + 1) {
    "form.#i#" = FORM[i];
    }
</cfscript>

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top