QueryStringDeleteVar(variable [, qs])
Last updated February 24, 2002
Version: 1 | Requires: ColdFusion 5 | Library: StrLib
Description:
Delete a variable (or a set of variables) and its value from a query string. By default, it uses the cgi.query_string, but you can pass in an optional second argument to replace the query string.
This function is handy when you need to preserve an entire query string, but you want to kill off one of the variables. For example, if you have a button that appends "logout=yes" to the existing URL and you want to preserve that URL but no longer have the logout variable.
Return Values:
Returns a string.
Example:
<cfoutput>
#queryStringDeleteVar("arg1",qs)#<br>
#queryStringDeleteVar("arg1,arg4",qs)#<br>
</cfoutput>
Parameters:
| Name | Description | Required |
|---|---|---|
| variable | A variable, or a list of variables, to delete from the query string. | Yes |
| qs | Query string to modify. Defaults to CGI.QUERY_STRING. | No |
Full UDF Source:
<cfscript>
/**
* Deletes a var from a query string.
* Idea for multiple args from Michael Stephenson (michael.stephenson@adtran.com)
*
* @param variable A variable, or a list of variables, to delete from the query string.
* @param qs Query string to modify. Defaults to CGI.QUERY_STRING.
* @return Returns a string.
* @author Nathan Dintenfass (michael.stephenson@adtran.comnathan@changemedia.com)
* @version 1.1, February 24, 2002
*/
function queryStringDeleteVar(variable){
//var to hold the final string
var string = "";
//vars for use in the loop, so we don't have to evaluate lists and arrays more than once
var ii = 1;
var thisVar = "";
var thisIndex = "";
var array = "";
//if there is a second argument, use that as the query string, otherwise default to cgi.query_string
var qs = cgi.query_string;
if(arrayLen(arguments) GT 1)
qs = arguments[2];
//put the query string into an array for easier looping
array = listToArray(qs,"&");
//now, loop over the array and rebuild the string
for(ii = 1; ii lte arrayLen(array); ii = ii + 1){
thisIndex = array[ii];
thisVar = listFirst(thisIndex,"=");
//if this is the var, edit it to the value, otherwise, just append
if(not listFind(variable,thisVar))
string = listAppend(string,thisIndex,"&");
}
//return the string
return string;
}
</cfscript>
Search CFLib.org
Latest Additions
Shawn Porter added
DeMoronize
3 hour(s) ago
Chris Carey added
readPropertiesFi...
1 day(s) ago
Randy Johnson added
lastDayofWeek
3 day(s) ago
Frank Marion added
sitemapPing
7 day(s) ago
Top Rated
QuickSort
Rated 5.0, 3 time(s)
indentXml
Rated 5.0, 3 time(s)
queryColumnsToSt...
Rated 5.0, 3 time(s)
generateSsccAsn
Rated 5.0, 3 time(s)