Ok, I have a huge application I spent about 6yrs (initially was a CGI based app).
Any ways...
I added a function to create custom form fields. All is smooth working nice as expected. Except, I am having issues with one thing.
I want the user to be able to use more than one set of checkboxes.
How I am building the checkboxes.
First I am finding out what form field to create:
function buildFormField($list){
switch($list['form_type']){
case 'select':
$form_field = buildSelect($list['cfid'], $list['form_values']);
break;
case 'radio':
$form_field = buildRadio($list['cfid'], $list['form_values'], $list['form_req'], $list['form_name']);
break;
[b]case 'checkbox':
$form_field = buildCheckbox($list['cfid'], $list['form_values'], $list['form_req'], $list['form_name']);
break;[/b]// Build checkbox
case 'textfield':
$form_field = "<input type=\"text\" name=\"custom" . $list['cfid'] . "\" class=\"input\" size=\"35\"";
if($list['form_req'] == 'yes'){
$form_field .= " alt=\"blank|" . unclean_value($list['form_name']) . "\"";
}
$form_field .= ">";
break;
case 'textarea':
$form_field = "<textarea name=\"custom" . $list['cfid'] . "\" cols=\"30\" rows=\"5\" class=\"textarea\"";
if($list['form_req'] == 'yes'){
$form_field .= " alt=\"blank|" . unclean_value($list['form_name']) . "\"";
}
$form_field .= "></textarea>";
break;
}
return ($form_field);
}
Ok,here we build the checkboxes.
function buildCheckbox($cfid, $form_values, $form_req, $form_name){
$form_vals = @explode("\r", $form_values);
for($l = 0; $l < count($form_vals); $l++) {
$checkbox .= "<input type=\"checkbox\" class=\"checkbox\" name=\"custom" . $cfid . "[]\" value=\"" . $form_vals[$l] . "\"";
if($form_req == 'yes'){
$checkbox .= " alt=\"checkbox|1|<:OPTIONS:>|" . unclean_value($form_name) . "\"";
}
$checkbox .= "><span class=\"small\">" . $form_vals[$l] . "</span> \n";
}
return(str_replace('<:OPTIONS:>', $l, $checkbox));
}
Trying to make it a 'customIDNum[]' array.
When submitted, this is how I am getting then sending the info:
$query = $db -> query("SELECT cfid, form_name, form_type FROM " . CUSTOM_FORM_TABLE . " ORDER BY cfid");
while ($cform = $db -> fetch_array($query)) {
$custom = "custom$cform[cfid]";
$custom = "${$custom}";
if(value_exists($custom)){
if($cform['form_type'] == 'checkbox'){
$info = '';
for($x = 0; $x < sizeof($custom); $x++) {
if($x >= 1){
$info .= ", ";
}
$info .= $custom[$x];
}
} else {
$info = $custom;
}
$message .= unclean_value($cform['form_name']). ": " . $info . "\n";
}
}
Im aware of working with and doing named values of for example:
name="delcat[]" value="myCat" . $id
I am just having an issue with getting:
$custom = "custom$cform[cfid]";
$custom = "${$custom}";
Values from the checkbox. Ideally, I could just do checkbox[]. But then they can only use one set of checkboxes.
Any one having any insight in what I maybe be missing. It is usually a deal with me overlooking something by trying to damn hard. I know I have done this before, I think. LOL!!!
It is only returning 'A' of 'Array'.
Thanks in advance!