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...


  • Ok, so you've added two lines to the form() to initialize the field if it's a new control, and a line to register a checkbox control for 'multiple' property. Then in the update() method you've added a line like $object->multiple = !empty($values['multiple']); If that's the case, the value/property should be stored in the 'forms_control table...all control properties/settings (an array) are serialized into the table's 'data' field. Therefore the control should be displayed as 'multiple' and return the data...however since we do not 'parseData()' nor 'templateFormat()' it, it might behave oddly. E.g., the 'response' on confirm_data isn't expecting an array of data...therefore it isn't passed onto submit_data since we aren't parsing it as an array.

    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.

    View article...
  • What I have done (and yesterday it stored the value once ?!):

    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);


    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...
  • Most likely the 'multiple' not being checked is a checkbox regression bug which hasn't been released yet (2.3.3 should be out by the end of the week since it is too large to be a patch to 2.3.2)

    View article...
  • I meant to say the 'fix' for the checkbox regression bug won't be release until later this week.

    View article...
Sign In or Register to comment.