Scripting - Multiple Checkbox Variables - Help required

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
nerdweed
Posts: 648
Joined: 25 Feb 2012 07:47
Location: XY64 Latest Beta , Win 11, 96dpi, 100%

Scripting - Multiple Checkbox Variables - Help required

Post by nerdweed »

I am having a script with multiple settings. Currently, I am presenting this settings in separate prompts - inputselect with checkbox

$g_rating = "1|2|+3|+4|5" ;
$rating = inputselect("Display files with ratings", $g_rating , |, 2, );
$options = "Green|+Yellow|Blue" ;
$cat = inputselect ("Choose Categories", $options, "|", 2,);
$current = "+Consider Ratings|Modified Recently|Consider Labels" ;
$setting = inputselect ("Settings", $current, "|", 2, , , , "Settings");


I trust this can be consolidated into a single html form. Any help with presenting this in a single form and separating the output would be great.

highend
Posts: 14950
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Scripting - Multiple Checkbox Variables - Help required

Post by highend »

I've written several scripts that use a html form to present options.

E.g.: http://www.xyplorer.com/xyfc/viewtopic.php?f=7&t=12364
http://www.xyplorer.com/xyfc/viewtopic.php?f=7&t=11197

or a more simple one:
http://www.xyplorer.com/xyfc/viewtopic.php?f=7&t=11235

and Stefan wrote a tutorial for displaying forms in html:
http://www.xyplorer.com/xyfc/viewtopic. ... hilit=html

If you have questions afterwards, ask :)
One of my scripts helped you out? Please donate via Paypal

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Scripting - Multiple Checkbox Variables - Help required

Post by bdeshi »

In: $g_rating, $options, $current. Out: $rating, $cat, $setting.

Code: Select all

	$g_rating = "1|2|+3|+4|5" ;
	$options = "Green|+Yellow|Blue|Magenta|Brown|Gray|White|Dark Knight" ;
	$current = "+Consider Ratings|Modified +Recently|Consider Labels|Consider Tags" ;
/*	$rating = inputselect("Display files with ratings", $g_rating , |, 2, );
	$cat = inputselect ("Choose Categories", $options, "|", 2,);
	$setting = inputselect ("Settings", $current, "|", 2, , , , "Settings");*/
	$ratingform='';$catform='';$settingform='';
	foreach ($i, $g_rating, "|"){
		if (strpos($i,"+") == 0) {$chk = ' checked';$i = substr($i, 1);} else {$chk = '';}
			$ratingform = $ratingform."<input type=""checkbox"" name=""rating"" value=""$i""$chk>$i<br>";
	}
	foreach ($i, $options, "|"){
		if (strpos($i,"+") == 0) {$chk = ' checked';$i = substr($i, 1);} else {$chk = '';}
			$catform = $catform."<input type=""checkbox"" name=""cat"" value=""$i""$chk>$i<br>";
	}
	foreach ($i, $current, "|"){
		if (strpos($i,"+") == 0) {$chk = ' checked';$i = substr($i, 1);} else {$chk = '';}
			$settingform = $settingform."<input type=""checkbox"" name=""setting"" value=""$i""$chk>$i<br>";
	}
	unset $i;

	$form = html(<<<#HEREDOCBOUNDARY
	<!DOCTYPE html><head><meta charset="UTF-8"><title>Checkboxes</title>
	<style>
	body       {font-family:sans-serif;font-size:11px;}
	div#boxes  {position:relative;width:250px;height:238px;margin:auto;}
	div#flds1  {position:absolute;left:4px;top:4px;width:64px;height:120px;border:1px dashed #767676;overflow:auto}
	div#flds2  {position:absolute;left:74px;top:4px;width:170px;height:120px;border:1px dashed #767676;overflow:auto}
	div#flds3  {position:absolute;left:4px;top:128px;width:240px;height:100px;border:1px dashed #767676;overflow:auto}
	span.desc  {font-size:9.5px;padding-left:8px;border-bottom:1px solid #acacac;}
	</style></head><body>
	<div style="width:250px;margin:auto;padding-bottom:6px">descriptions. Narration. Prose. blah bla blah<br></div>
	<div id="boxes">
	<form method="get" action="xys:">
		<div id="flds1">
			<span class="desc">ratings <br></span>
			$ratingform
		</div>
		<div id="flds2">
			<span class="desc">categories <br></span>
			$catform
		</div>
		<div id="flds3">
			<span class="desc">settings <br></span>
			$settingform
		</div>
		<input style="position:fixed;right:0px;bottom:0px;text-align:center;width:100%" type="submit" value="Submit">
	</form>
	</div>
	<div style="width:250px;margin:auto;padding-bottom:6px;font-size:7px;color:#898989">psst, positioning is eveyrthing here!</div>
	</body></html>	#HEREDOCBOUNDARY, 256, 400, "Multiple Checkbox Variables");
	//$form example: ?rating=3&rating=4&cat=Green&cat=Yellow&setting=Consider+Ratings&setting=Modified+%2BRecently

	$form = substr($form, 1); //remove preceding '?'
	$rating = '';$cat ='';$setting='';

	foreach($token, $form, '&'){
		if (gettoken($token, 1, '=') == 'rating'){
			$rating = $rating.urldecode(gettoken($token, 2 , '=')).'|';
		} elseif (gettoken($token, 1, '=') == 'cat'){
			$cat = $cat.urldecode(gettoken($token, 2 , '=')).'|';
		} elseif (gettoken($token, 1, '=') == 'setting'){
			$setting = $setting.urldecode(gettoken($token, 2 , '=')).'|';
		}
	}
	unset $form, $ratingform, $catform, $settingform, $token;
	$rating = trim($rating,'|');$cat = trim($cat,'|');$setting = trim($setting,'|');
	text '[key:$rating<crlf>$categories<crlf>$settings]'.<crlf>.$rating.<crlf>.$cat.<crlf>.$setting;
[/size]
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

nerdweed
Posts: 648
Joined: 25 Feb 2012 07:47
Location: XY64 Latest Beta , Win 11, 96dpi, 100%

Re: Scripting - Multiple Checkbox Variables - Help required

Post by nerdweed »

Thanks Highend. It helped me and managed to get in working.

Thanks Sammay for working on this. Will check your code and update mine accordingly.

Post Reply