Ren44
Ren44

Reputation: 107

Coldfusion 9 - Checkbox values from form to replace parameter value/s

Very new to coldfusion. So I have a a form outputs values from DB into checkboxes.

<cfoutput query="Offices">
         <label><input type="checkbox" value="#offices#" name="Offices">#offices#</label>
</cfoutput>

and when a user selects more than one checkbox it passes multiple parameters into URL which looks like this:

offices.cfm?Offices=A&Offices=B&Offices=C

I am trying to prevent multiple of the same parameters being passed so I want it to return like:

offices.cfm?Offices=A,B,C&...

I am really struggling to figure this out. Help is appreciated.

Upvotes: 1

Views: 338

Answers (1)

Leigh
Leigh

Reputation: 28873

(Summary from comments, just to close out this thread ...)

True, but that is just how the parameters are transmitted in the url. Per the html specs, when using method GET, the browser builds a builds a big string of name/value pairs for all (successful) form fields. Then appends them to the url as the query string:

Submit the encoded form data set

If the method is "get" and the action is an HTTP URI, the user agent takes the value of action, appends a ? to it, then appends the form data set, encoded using the "application/x-www-form-urlencoded" content type.

form data set

A form data set is a sequence of control-name/current-value pairs constructed from successful controls

However, it does not matter that the field name appears multiple times in the URL. If you dump the #URL# scope, you will see that CF has already parsed those values into a single CSV list for you. That list can be accessed using the variable name URL.Offices.

Upvotes: 1

Related Questions