List2URLToken(fields[, excluded][, delim])
Last updated September 20, 2004
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 "Exclude List" 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;
}
Search CFLib.org
Latest Additions
Raymond Camden added
QueryDeleteRows
November 04, 2017
Leigh added
nullPad
May 11, 2016
Raymond Camden added
stripHTML
May 10, 2016
Kevin Cotton added
date2ExcelDate
May 05, 2016
Raymond Camden added
CapFirst
April 25, 2016