Having been working with Travis at Build with Structure on Structure Development and Bug Fixes for the past 9 months or so, there’s been a pattern emerging in a supposed ‘bug’ with structure thats not actually the case.

After having responded numerous times on various support tickets as to the resolution, I decided (in absence of a blog on the Structure site) that a post detailing the issue would be a good idea.

The bug is surrounding the drag and drop reordering of structure entries.

The drag and drop functionality is accomplished through a heavily stylised version of nestedSortable.

The way that it works is that every time you drop an entry into a new location, it triggers a post back to ExpressionEngine which contains EVERY Structure controlled Entry ID and it’s new (calculated) order in the tree.

Some users have been experiencing issues after they drag and drop that, upon refresh, some entries disappear or move out of position and cause problems.

The common cause of this problem is due to a PHP variable addition that was introduced in PHP 5.3.9

max_input_vars

This defines how many input variables may be accepted (applied separately to $_GET, $_POST and $_COOKIE superglobals).

The reason for this was to mitigate the possibility of Denial of Service attacks which use hash collisions.

The result of which (and here’s the key) is that the default value of this is set to 1000 variables and input variables set 1000+ are truncated (removed) from the post data.

Therefore, if you have a particularly large site with 1000+ structure entries, you will likely be incurring this problem when you drag and drop reorder.

Similarly, if you use a hardened PHP implementation such as suhosin, it’s highly likely that the configuration has been set to an arbitrary value which may be causing you problems.

There are two main solutions to fixing the problem - one is relatively straight forward, however the other may require system administrator assistance.

.htaccess update

Probably the easiest of the two. In your .htaccess file, simply add the following line of code:

php_value max_input_vars 5000

for suhosin implementations you should use the following:

php_value suhosin.get.max_vars 5000 php_value suhosin.post.max_vars 5000 php_value suhosin.request.max_vars 5000

(Note: the 5000 value above is an arbitrary value for demonstration - you should set the value to something more suitable for your site).

php.ini update

If the .htaccess doesn’t work, you’ll more than likely need to update the php.ini on your server to increase the values. Instructions on this vary on every site implementation, so would be advisable to send this post to your system administrator or server admin.

Once you’ve made this update, you should notice that the drag and drop functionality will work again as expected.

I am adding an internal function into a later version of structure, which will display a warning to users when they get close to the max_input_vars limit which should hopefully alleviate these reports - however for the time being, this blog post should help.