This has been spliced from http://drupal.org/node/53351

To reproduce:
-Create a multi-select vocabulary and associate it with a node type. Populate it with a few terms.
-Create a node of this type and associate it with some of the above terms.
-Edit the node, remove all the terms from said vocabulary. Click Preview or submit.
-The changes are not saved and the default values are stored.

It is assumed that the issue linked above has been committed..

-K

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Zen’s picture

Assigned: Unassigned » Zen
Status: Active » Needs review
FileSize
1.08 KB

I don't really grok form.inc, but here's a shot at this. Patch attached.

I'm not sure of the ramifications of this - esp. w.r.t. multipart forms, nor am I sure about the needs_validation statement. Please test thoroughly.

Thanks
-K

Zen’s picture

Another approach?

Please review both patches.

Thanks
-K

chx’s picture

Assigned: Zen » chx
Status: Needs review » Needs work
kkaefer’s picture

Both patches from Zen work for me flawlessly. I'd take the second patch though.

jvandyk’s picture

Status: Needs work » Needs review
FileSize
701 bytes

Second patch works. Tested with multiple multiple-select vocabularies. This patch is the same; just makes comment style and terminology consistent.

chx’s picture

Title: Forms system: Unable to clear existing values from a multi-select form element » Clean and harden form_builder for various types of posted elements
Category: bug » task
FileSize
1.11 KB

Now you can not temper with a simple checkbox, before it was not checked. We remove linebreaks from mere textfields, there is no way this breaks user data, only hackers are interested. This puts many header injection attacks at rest. And yes, we care for empty selects. And last, but not least, we make the whole thing readable.

kkaefer’s picture

chx' patch works for me.

Dries’s picture

How about:

+              $form['#value'] = trim($edit);

instead of:

+              $form['#value'] = str_replace(array("\r", "\n"), '', $edit);
kkaefer’s picture

Dries, trim does only remove leading or trailing whitespace, not line breaks within the string. Probably use both.

Zen’s picture

Patch applies cleanly. Testing:

  • #requireds work as expected on all elements.
  • Clearing checkbox groups works fine.
  • Clearing selects works fine.

+1

-K

chx’s picture

Dries, you do not want to merely remove the ending \r \n but all instances of them. On the other hand, you do not want to remove spaces in the beginning for example. So I fail to see how trim is appropriate here.

Dries’s picture

Nevermind my comment. chx is right. :)

Dries’s picture

Status: Needs review » Fixed

Tested the patch. Committed to HEAD.

moshe weitzman’s picture

Title: Clean and harden form_builder for various types of posted elements » #required not working for checkbox
Status: Fixed » Active

Zend said: "#requireds work as expected on all elements."

The required it on a checkbox is being ignored. The use case for required checkbox is on trms of service agreements and so on. The user should not pass validation until checkbox is checked.

Further, the CSS on a required checkbox is different from other form elements and thus isn't getting styled properly.

Not sure if this report belongs here but is good for now. At least is out of my head.

moshe weitzman’s picture

for testing, the easiest way to add a required checkbox is to use admin/settings/profile

moshe weitzman’s picture

Title: #required not working for checkbox » required checkbox not stylized like a required field
Priority: Critical » Minor

oops. my checkout was stale. the validation works now. class attribute is different though and appears unrequired in bluemarine

LAsan’s picture

Version: x.y.z » 7.x-dev

chx: Still an active task?

alexanderpas’s picture

Status: Active » Closed (fixed)

seems fixed to me, using the method from #15 the indicator displayed correctly.