[join_params]

Description

Link: [join_params]
Author: Dominique Guardiola
Category: Array
Version: 8.5.x
License: Public Domain
Posted: Apr. 08, 2008
Updated: Apr. 08, 2008
More by this author...

This ctag merges the GET and POST parameters of a submitted form, and re-arrange the parameters to group in one value the repeated items coming from input checkboxes or multiple selects.

It returns an array ready for include in your inline, given the name of the parameters match your database fields names.
You can filter the arguments from the POST/GET submission using an array of unwanted names (name=value pairs which don't match any field in your db, or false fields used in your form).
The default separator is a comma (',') but you can choose another.

Parameters

-unwanted array, optional array of the names of unwanted arguments
-sep string, optional custom separator character

Sample Usage

//full client_params, repeating fields joined :
join_params;


//for this form POST :     
    * pair: (choice)=(20058)
    * pair: (choice)=(103)
    * pair: (choice)=(8887)
    * pair: (update)=(news)
    * pair: (id)=(007)
    * pair: (cookie)=(yes)

join_params(-unwanted=array('cookie','update'), -sep='|');

//will return :

array: (pair: (id)=(007)),(pair: (choice)=(20058|103|8887))
						

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
define_tag(
	'params',	
	-optional='unwanted',
	-optional='sep',
	-namespace='join_',
	-priority='replace',
	-description='Join multiple POST or GET arguments with the same name under the same value, using a custom separator.'
	);
	
	local('merged_params') = array;
	#merged_params->merge(client_getparams);
	#merged_params->merge(client_postparams);

	!local_defined('sep') ? local('sep')= string(',');
	!local_defined('unwanted') ? local('unwanted')= null;
	
	local('fields_map') = map;
	local('fields_array') = array;
	
	iterate: #merged_params, local('tmp');
		if: #unwanted !>> #tmp->first;	
			if: #fields_map !>> #tmp->first;	
				#fields_map->(insert: #tmp->first=#tmp->second);		
			else;		
				#fields_map->(insert:#tmp->first=(#fields_map->(find:#tmp->first))+#sep+#tmp->second);		
			/if;	
		/if;	
	/iterate;
		
	iterate:#fields_map, local('tmp');
		#fields_array->(insert:#tmp->first=#tmp->second);
	/iterate;
	
	return(#fields_array);

/define_tag;

 

Related Tags



Comments

none

Email:


Password:



Newest

Most Popular

Support tagSwap.net