Question

I have form uses HTMLEditFormat call for every single input fields. is there any way so I can call HTMLEditFormat function only once and it will take care of all input fields instead of adding it to every single field?

Was it helpful?

Solution

The following will accomplish your goal, but like has been pointed out in the comments section, this may not be your best option.

<cfset cleanForm = {}>
<cfloop list="#form.fieldnames#" index="i">
  <cfset cleanForm[i] = HTMLEditFormat(form[i])>
</cfloop>

Instead of referencing form.firstName you would now reference cleanForm.firstName

OTHER TIPS

No, you have to apply the HTMLEditFormat() function against each form value separately. But if you're currently writing out a line of code for each form field to do that:

cleanFormData.firstName= HTMLEditFormat(form.firstName)
cleanFormData.lastName= HTMLEditFormat(form.lastName)

You can revise your code to take advantage of the fact that all of those form values are in the form scope - which is essentially a ColdFusion struct variable - and you can write code that loops through the struct and applies HTMLEditFormat() against the form value in the current iteration.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top