[wp-trac] [WordPress Trac] #41502: _wp_expand_nav_menu_post_data() corrupts multiple select (array value)
WordPress Trac
noreply at wordpress.org
Wed Dec 13 23:29:50 UTC 2017
#41502: _wp_expand_nav_menu_post_data() corrupts multiple select (array value)
--------------------------------------+------------------------------
Reporter: elliotcondon | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Menus | Version: 4.9
Severity: normal | Resolution:
Keywords: has-patch has-unit-tests | Focuses: administration
--------------------------------------+------------------------------
Comment (by elliotcondon):
Hi @dd32
Thanks for the reply, I've glad you were able to replicate the issue.
This patch looks to be working for the basic example, but not for more
complicated scenarios.
Testing the basic example, everything looks to be working well:
{{{
<input type="text" name="testing[]" value="A">
<input type="text" name="testing[]" value="B">
Result:
[testing] => Array
(
[0] => A
[1] => B
)
}}}
However, there is another scenario where an issue occurs (slightly more
complicated, but just as common). When working on a plugin, it is best
practice to 'namespace' your $_POST data by writing input names like
`my[field_1]`;
I have found the following 2 issues:
'''Issue 1. Extra $_POST data.'''
When using a name-spaced input name, the $_POST data contains an extra
value. Note the 3rd bit of data is a duplicate:
{{{
<input type="checkbox" name="my[field_1][]" value="A"> A
<input type="checkbox" name="my[field_1][]" value="B"> B
Result:
[my] => Array
(
[field_1] => Array
(
[0] => A
[1] => B
[] => B
)
)
}}}
'''Issue 2. Hidden input breaks $_POST data.'''
When adding a list of checkbox or radio inputs, it is common to use a
hidden input above the list to allow an "empty" value to be saved. Doing
so prevents the array data from being interpreted:
{{{
<input type="hidden" name="my[field_1]" value="">
<input type="checkbox" name="my[field_1][]" value="A"> A
<input type="checkbox" name="my[field_1][]" value="B"> B
Result:
[my] => Array
(
[field_1] => Array
(
[] => B
)
)
}}}
Let me know how you go testing these 2 scenarios. Happy to help provide
any other info.
Question. Why do we need such a complicated
_wp_expand_nav_menu_post_data() function? If the form data is encoded into
a JSON string and sent via `$_POST['nav-menu-data']`, can't we just decode
this string and replace `$_POST['nav-menu-data']` with the array value?
Thanks
Elliot
--
Ticket URL: <https://core.trac.wordpress.org/ticket/41502#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list