[wp-trac] [WordPress Trac] #33331: Multiple input field values in Media Modal do not save collectively
WordPress Trac
noreply at wordpress.org
Mon Aug 10 22:11:19 UTC 2015
#33331: Multiple input field values in Media Modal do not save collectively
--------------------------+-----------------------------
Reporter: LindsayBSC | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Media | Version: 4.2.4
Severity: normal | Keywords:
Focuses: javascript |
--------------------------+-----------------------------
'''Problem''':
When adding custom fields that would typically pass an array value to
$_POST in the WordPress media upload modal window such as multiple
checkboxes or multiple select inputs, the 'save-attachment-compat' action
that was triggered "onblur" of each field would only pass that specific
value of that input and not the collective values of a multiple-input
field.
'''For example''':
A collection of checkboxes would send the input value for a checkbox group
for each box checked individually even if the name attribute is set up to
send it's value as an array using the format `name="field1[]"`
See results of $_POST:
[[Image(http://cl.ly/image/0b2F3U3l1U22/Screen%20Shot%202015-08-10%20at%205.08.54%20PM.png)]]
'''Replicate''':
Use this code to see the problem replicated
https://gist.github.com/Lindsayanng/dee0488120d436e5b43b
'''Fix''':
In the 'save' function of 'AttachmentCompat' I was able to check if an
input field has a name that ends with `[]` and if it does it combines all
values from that collection of inputs in to a javascript array object to
be passed to the $_POST variable at save time in the 'wp_ajax_save-
attachment-compat' action.
'''For Developers''':
To utilize multiple input field values your input must use `[]` in it's
naming convention as is expected when passing an array of values from a
form via PHP $_POST.
To store the value as a serialized array in your postmeta table you must
use `.serialize()` on your $_POST value before doing `update_post_meta`
--
Ticket URL: <https://core.trac.wordpress.org/ticket/33331>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list