form validate done incorrectly - and solution

liquidcms - August 18, 2009 - 04:56
Project:Creative Commons
Version:6.x-1.x-dev
Component:Code
Category:bug report
Priority:critical
Assigned:balleyne
Status:closed
Description

I think you are "adding" your form code incorrectly to the node form that the CC form is being added to:

    if (creativecommons_node_type_is_enabled($node->type)) {
        $form = array_merge($form, creativecommons_node_form($form['#node'], $form_state));
    }

array_merge isn't doing what you think here, if prior to merge one of the keys in the array already existed it will be wiped, not merged as you'd think, so even though $form['creativecommons'] gets added, $form['#validate'] and $form['#submit'] wipe out the existing values for these.

from php manual:

"If the input arrays have the same string keys, then the later value for that key will overwrite the previous one. If, however, the arrays contain numeric keys, the later value will not overwrite the original value, but will be appended. "

using array_merge_recursive() will do the right thing here.

#1

balleyne - August 25, 2009 - 11:41
Assigned to:Anonymous» balleyne
Status:active» fixed

Thanks! Just committed your recommended fix.

#2

System Message - September 8, 2009 - 11:50
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.