Page 1 of 1
Scripting - Multiple Checkbox Variables - Help required
Posted: 25 Sep 2014 14:09
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.
Re: Scripting - Multiple Checkbox Variables - Help required
Posted: 25 Sep 2014 14:23
by highend
Re: Scripting - Multiple Checkbox Variables - Help required
Posted: 25 Sep 2014 18:14
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]
Re: Scripting - Multiple Checkbox Variables - Help required
Posted: 25 Sep 2014 19:58
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.