Please disregard the 'View article...' shown at the bottom of many posts as this is the result of restoring old forum posts from a backup.
Making multi select possible in a drop down list control
I am trying to make it possible to select multiple items in a dropdown list on a form. I have added the multiple field to the control (in dropdowncontrol.php) in the form() and update() methods. I can them set it via a check box when adding the control to the form. the value is not yet stored however so when running the form the drop down list is still single select. I am trying to find where the controls is stored.
I have tried using a editor control to add a multiselect list to the form. The form itself works fine and the data is in the POST data. However when in the confirm_data or submit_data methods of the forms controller only the last selected value is available. in $this->params
View article...
I have tried using a editor control to add a multiselect list to the form. The form itself works fine and the data is in the POST data. However when in the confirm_data or submit_data methods of the forms controller only the last selected value is available. in $this->params
View article...
Comments
I'm not sure how you can get an 'editor' control on the form...but we only parse the $this->params for the specific controls we placed on the page.
If you could send me some more detailed data, I might be able to help troubleshoot as this feature could be welcome by other users and placed back into the main code base. dleffler@hughes.net
View article...
1. In the form() function, block if (!isset($object->identifier)) I have added $object->multiple = false;
2. Again in the form fustian when registering the controls I have added: $form->register("multiple", gt('Allow multiple selection.'), new checkboxcontrol($object->multiple,true));
3. In the update function I have added: $object->multiple = !empty($values['multiple']);
One time it saved the next time it;s not. If I look in the database at this moment it is set: s:8:"multiple";b:1
But when returning to editing the form control the checkbox is not checked. The control now is multiselect. although the edit control form does not show it.
The next step is indeed handling the data in the confirm and submit steps. For now I am checking if it is an array when extracting the values and then imploding them to a string. I have not yet tested that fully. For example I am not storing the form results in the database so I haven't tested that. And as is_array seems to be true most of the time it might implode values where I don't want it as well. For the simple form I have now it works.
I have done this in two places in the confirm_data function:
$value = call_user_func(array($coltype, 'parseData'), $col->name, $this->params, true);
if (is_array($value)) {
$value = implode(',', $value);
}
and
foreach ($this->params as $k => $v) {
// $this->params[$k]=htmlentities(htmlspecialchars($v,ENT_COMPAT,LANG_CHARSET));
if (is_array($v)) {
$v = implode(',', $v);
}
$this->params[$k] = htmlspecialchars($v, ENT_COMPAT, LANG_CHARSET);
}
and once in the submit function:
if (is_array($this->params[$c->name]))
{
$this->params[$c->name] = implode(',', $this->params[$c->name]);
}
$emailValue = htmlspecialchars_decode(call_user_func(array($control_type, 'parseData'), $c->name, $this->params, true));
View article...
View article...
View article...