#33331 closed defect (bug) (duplicate)
Multiple input field values in Media Modal do not save collectively
Reported by: | LindsayBSC | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Media | Keywords: | |
Focuses: | javascript | Cc: |
Description
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[]"
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
Attachments (1)
Change History (5)
#1
follow-up:
↓ 2
@
9 years ago
- Milestone Awaiting Review deleted
- Resolution set to duplicate
- Status changed from new to closed
- Version 4.2.4 deleted
Hello LindsayBSC, welcome to Trac!
Thanks for your detailed report and the patch. Looking at your patch and it seems like the indentation went wrong and you accidentally removed some lines.
We're already tracking this issue in #28053. Would you like to refresh your patch and upload it to #28053?
Please note, that media-view.js is auto-generated and the source for the compat code is in trunk/src/wp-includes/js/media/views/attachment-compat.js.
#2
in reply to:
↑ 1
@
9 years ago
Ah yep. You're right. My patch definitely did go wrong.
Also, I feel like I searched for DAYS! I can't believe I did not come across that ticket! I am aware that media-views.js is auto-generated. I don't have the attachment-compat.js in the release version of WP. Should I use the trunk file and submit it as a patch to trunk instead?
Replying to ocean90:
Hello LindsayBSC, welcome to Trac!
Thanks for your detailed report and the patch. Looking at your patch and it seems like the indentation went wrong and you accidentally removed some lines.
We're already tracking this issue in #28053. Would you like to refresh your patch and upload it to #28053?
Please note, that media-view.js is auto-generated and the source for the compat code is in trunk/src/wp-includes/js/media/views/attachment-compat.js.
media-views.js file patch