CFLib.org – Common Function Library Project

List2URLToken(fields[, excluded][, delim])

Last updated September 20, 2004

author

Joshua Miller

Version: 1 | Requires: CF5 | Library: StrLib

Description:
List2URLToken creates a QueryString from a specified list. Each item in the list should be the name of an existing variable. The optional parameter EXCLUDE allows you to pass another list of values you do not want included in the QueryString. Accepts optinal delimiter as well. I use this for transforming form.fieldnames into a QueryString to pass to a NEXT-N tag, however this can be used with ANY list instead of only form fields.

Return Values:
Returns a string.

Example:

<cfscript>
fname="Mr. William";
minit="S";
lname="Burroughs";
go="GO";
fieldlist="fname,minit,lname,go";
excludelist="go";
</cfscript>
<cfoutput>#list2UrlToken(fieldlist,excludelist)#</cfoutput>

Parameters:

Name Description Required
fields List of variables to loop over. Yes
excluded Variables to ignore. No
delim Delimiter to use. Default is the comma. No

Full UDF Source:

/**
 * Converts a list into a QueryString. Allows an &quot;Exclude List&quot; as well.
 * 
 * @param fields 	 List of variables to loop over. (Required)
 * @param excluded 	 Variables to ignore. (Optional)
 * @param delim 	 Delimiter to use. Default is the comma. (Optional)
 * @return Returns a string. 
 * @author Joshua Miller (josh@joshuasmiller.com) 
 * @version 1, September 20, 2004 
 */
function List2UrlToken(fields){
	// Set Local Variables
	var token="";
	var excluded="";
	var delim=",";
	var i = 1;
	var tmpObj = "";
	
	if(arrayLen(arguments) gte 2) excluded = arguments[2];
	if(arrayLen(arguments) gte 3) delim = arguments[3];
	
	// Begin Processing
	for(i=1;i LTE listlen(fields,delim);i=i+1){
		if(not ListFind(excluded,listgetat(fields,i,delim))){
			tmpObj=listgetat(fields,i,delim);
			if(len(token)) token="#token#&#tmpObj#=#urlEncodedFormat(evaluate(tmpObj))#"; 
			else token="#tmpObj#=#URLEncodedFormat(evaluate(tmpObj))#"; 
		}
	}
	return token;
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson