Posted by Dave Reid on September 30, 2008 at 7:12am
| Project: | Drupal core |
| Version: | 8.x-dev |
| Component: | system.module |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Dave Reid |
| Status: | needs review |
| Issue tags: | DrupalWTF |
Issue Summary
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 |
Comments
#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
#11
Adding WTF tag.
#12
Unless chx provided some hidden reasoning that's not stated here, I think that #element_validate is perfectly correct here.
Lovely patch! Just a bit old. Anyone up for re-rolling?
#13
subscribing
#14
Too late for D7.
#15
Agreed, although I'm still interested in helping fix.
#16
Related #1120306: Do not save array_filter in system_settings_form_submit()
#17
subscribe
#18
I kind of re-rolled to 8.x
I didn't know what to do with update function on .install, is it needed for D8?