because i have values being send as: cityp[: 'MB',...
# cfml-general
g
because i have values being send as: cityp[: 'MB', city[]:'VC'
a
OK, first thing... try to remember to put everything for one topic in a thread, secondly I think I worked out what you meant in yer earlier comment I asked about. There's nothing special about form field names with
[]
at them. They get posted exactly the same as any other field. So if you have
<select name="city[]">
(etc), then the value will be put into the form scope as
city[]
. Because
city[]
contains the
[]
which can't be used in a dot-notation struct key reference, you'll need to use bracket notation to access them, eg:
form["city[]"]
m
back in the day prior to sameformfieldsasarray I utilized a hack to combine same named fields into a single array element. This was written ages ago for a CF10 application. I switched to CFSCRIPT syntax to share, because i believe this type of logic should not be in tags. Just my opinion...
Copy code
<cfscript>
function fixFormScope()
{
       var tmpParams = getPageContext().getRequest().getParameterMap();
	var i = "";
	if ( StructIsEmpty(tmpParams) )
		fixFormScopeMultiPart();
	else
	{
		cfloop ( collection=tmpParams, item="i")
		{
			if (  StructKeyExists(FORM, i) )
				form[i] = tmpParams[i];			
		}		
	}
}
function fixFormScopeMultiPart()
{
	var tmpArr = FORM.getPartsArray();
	var i = "";
	var tmpForm = {};
	cfloop ( array=tmpArr, index="i" )
	{
		if (  i.IsParam() )
		{
			if (  StructKeyExists(tmpForm, i.getName()) )
			{
				if (  not IsArray(tmpForm[i.getName()]) )
				{
					tmpForm[i.getName()] = [tmpForm[i.getName()]];
				}
				ArrayAppend(tmpForm[i.getName()], i.getStringValue());
			} else {
				tmpForm[i.getName()] = i.getStringValue();
			}
		}
	}
	cfloop ( collection=tmpForm, item="i")
	{
		form[i] = tmpForm[i];
	}
}
</cfscript>
g
nice & thanks, I updated my jquery script to handle that form data, but the code you shared is very Nice and handy and thanks for that