Replace $form['array_filter'] hack with #element_validate
Dave Reid - September 30, 2008 - 07:12
| Project: | Drupal |
| Version: | 7.x-dev |
| Component: | system.module |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Dave Reid |
| Status: | needs work |
Description
I noticed that when I am using
<?php
$form['array_filter'] = array('#type' => 'value', '#value' => TRUE);
?>in my forms with checkboxes, that there is a variable 'array_filter' being saved into my variables table.
I looked back at some of the history of array_filter issues, and noticed that #41170: Don't save junk as variables during settings save was meant to fix this, but a different fix was committed that does not prevent the saving of array_filter. The attached patch modifies system_settings_form to not save the 'array_filter' form option as a variable.
| Attachment | Size | Status | Test result | Operations |
|---|---|---|---|---|
| array_filter-D7.patch | 1.46 KB | Ignored | None | None |

#1
This bug is also present in D6 and D5 and should be backported if this is deemed an acceptable solution.
#2
Here are the D5 and D6 patches for this issue just for kicks. Don't hurt me testing bot...
#3
Here is another proposed solution, that removes the FAPI hack 'array_filter' and adds a new function drupal_filter_array() in form.inc that can be used with #element_validate:
<?php$form['item']['#element_validate'] = array('drupal_filter_array');
?>
#4
I love #3, that's so Form API compliant :)
We should include an update function that remove array_filter from the variable table.
#5
New patch:
- Adds a function drupal_filter_form_array that replaces the FAPI hack $form['array_filter'] with
$form['item']['#element_validate'] = array('drupal_filter_form_array');- Adds system_update_7011 to delete the unwanted 'array_filter' variable that was accidentally saved.
- Picked up a few coding space standard issues.
#6
Renaming for new direction and bump for review or thoughts. Anyone?
#7
#8
According to the recommendations of chx in IRC, it's better to use
#process. Any#processhandlers attached to a specific element are executed before they are processed.#9
I need some help with this...I have no idea how to get #process working to filter array values on submission... Where's my patch status of 'code needs help'? :)
#10