This is because you convert a 'select' element into a 'value' element, but without changing the '#default_value' to '#value', here is a proper way to do it, patch attached.

Comments

pounard’s picture

You can even remove the unset( .. ) line just under the last +'ed line.

bradweikel’s picture

Status: Needs review » Postponed (maintainer needs more info)

pounard -- I'm no expert on Form API, so can you clarify how you know that it isn't validating? Your patch makes sense but I want to be sure I understand the issue.

pounard’s picture

This is a rather old isssue. If I remember well, this is something like this:

When you do this:

$form['taxonomy'][$vid]['#type'] = 'value';

You pragmatically transform a 'select' type element into a value element. If you look deeper into the form API reference, you'll see that a 'value' element should have the '#value' property, not the '#default_value'.

Generally speaking, #value implies that the value can not be changed by the user, but #default_value assume that the user can change it. By definition, a 'value' element type can never be changed, so you need to set the '#value' property instead of the '#default_value' of the legacy 'select' element from the taxonomy form.

By creating a new element from scratch, I also remove some garbage that the form API won't use for the 'value' typ'ed elements, such as the '#options', and also do some cleaning (it might remove some validations functions as well, which you don't need because a 'value' element carries a fixed value which won't need any validation).

The side effect (on my box, can't remember the PHP version because I changed since) was a WSOD (PHP crash) an your module was unusable then.

bradweikel’s picture

Version: 6.x-1.1-beta2 » 6.x-2.x-dev
Status: Postponed (maintainer needs more info) » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.