validation of required fields fails

ceaker - November 21, 2008 - 21:20
Project:Addresses
Version:6.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Description

Drupal Core 6.6

Other installed modules:
CCK 6.x-2.1
Contemplate 6.x-1.0
Date 6.x-2.0-rc4
Email Field 5.x-1.1
Token 6.x-1.11
Views 6.x-2.1

I have configured several addresses subfields (in my case, City, Street, Postal Code, and Phone) as 'required' in the CCK node type definition. However, when I create a node of the new type and leave those fields blank, Drupal creates the node just fine. My expectation was that when I submit the node for creation, I would get a error telling me those fields are required. This seems like either a code issue (assuming I'm correct) or documentation help issue (assuming I'm mistaken).

Also, on the create node form, I noticed that these fields did not have the asterisk that normally displays next to required fields.

#1

ceaker - November 21, 2008 - 21:23

Sorry, the Email Field version is 6.x-1.1, not version 5 as listed above.

#2

deviantintegral - February 7, 2009 - 03:51
Version:6.x-1.0-alpha3» 6.x-1.05

I'm encountering the same issue. This is important as we want to require users to provide a physical address. In my case, we're using the Content Profile module to create profile nodes for users, not the module included with this one.

#3

deviantintegral - February 7, 2009 - 04:14
Version:6.x-1.05» 6.x-1.x-dev
Status:active» postponed (maintainer needs more info)

I've found a fix, if not the underlying issue, and it's in the latest development version as well.

At line 167 in addresses.module:

  // Reset the required fields based on the general required value
  if (empty($element['#required'])) {
    foreach ($fields as $field => $required) {
      if ($required == ADDRESSES_FIELD_REQUIRED) {
        $fields[$field] = ADDRESSES_FIELD_SHOW;
      }
    }
  }

This seems to be removing the required values from each field. If I comment out line 167, it seems to work as expected. I'm not too sure what the purpose of the code is; I took a look at the annotate logs and the comment wasn't really enlightening.

@brmassa: Is there an issue number which matches with version 1.25 of that file? Based on what I can tell, I think the fix is to remove that whole bit of code, but I'm sure there's something else going on I haven't picked up on yet. Let me know and I'll roll up a patch.

Thanks!

#4

deviantintegral - February 8, 2009 - 19:03
Status:postponed (maintainer needs more info)» needs review

I think I figured out what this was trying to do based on an issue discovered by my above hack. When you comment that line, required fields end up requiring default values on the field configuration form. So here is a patch which lets the fields be required on normal nodes, and demotes them to ADDRESSES_FIELD_SHOW on the field configuration form.

AttachmentSize
337541_required_fields_validation.patch 552 bytes

#5

recidive - February 11, 2009 - 05:15
Status:needs review» reviewed & tested by the community

Good catch!

Patch fix the problem.

Not sure if there are any regressions, but this looks ready to go.

#6

brmassa - February 11, 2009 - 07:24
Status:reviewed & tested by the community» fixed

Guys,

thanks a lot. i just commited the patch on CVS. soon on the next release.

regards,

massa

#7

System Message - February 25, 2009 - 07:30
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.