This is driving me mad. I have a form that returns search results that also re-draws the same form for additional searching right after the results. I'm using the forms API "checkboxs" type. The user can select some or none of the checkboxes. I'm using 4.7.5

  • When my forms api "checkboxs" list have selections made already, and the user de-selects them all, everything is ok.
  • But when that page is again submitted where the checkboxes were empty to start with when the page was first drawn, I get an extra 1 in the result array!

This is my hook_submit:

function project_finder_form_submit($form_id, $form_values) {

  //dprint_r is from the devel module for debugging
  dprint_r($form_values);

  $locationList = '';

  if (is_array( $form_values['phaselist']  )) {
    $phaseList = convert_array_to_comma_delimited_string($form_values['phaselist']);
  }

  .
  .

I do not tamper with the result set. And look at what I get back from the devel debug function: What the heck are those extra array entries in my submit result???

Array
(
    [keywords] => 
    [phaselist] => Array
        (
            [] => 1
            [1] => 0
            [2] => 0
            [3] => 0
            [4] => 0
        )

    [countries] => Array
        (
            [] => 1
            [17] => 0
            [18] => 0
            [19] => 0
            [23] => 0
            [60] => 0
            [20] => 0
            [21] => 0
            [22] => 0
            [16] => 0
        )

This is doing a lot of harm to my code - can anyone reproduce this?

Comments

bpocanada’s picture

Nothing extra, Default value setting in checkbox bringing that. If you don't wan't any default values to come up when user not checked any of that then do not put #default_values in checkbox form array.

heine’s picture

Project: Drupal.org infrastructure » Drupal core
Version: » 4.7.5
Component: Other » forms system

Rreassigning to the right project.

jmanico’s picture

Thats for putting this in the right category.

As my bug states, I need to set default values, I do it correctly, and I NEVER have an empty element in my code ever, but I still see

[] => 1

back from the result. I coded around this by walking keys, but it seems to me that this is a bug with the drupal core, still.

heine’s picture

Status: Active » Postponed (maintainer needs more info)

I cannot reproduce this.

Can you please post sample code that reproduces the problem? Any additional information is welcome.

pasqualle’s picture

Status: Postponed (maintainer needs more info) » Closed (won't fix)

This version is not supported. Reopen or create a new issue if the problem exists in any recent version (version equal or above Drupal 5)