Closed (fixed)
Project:
Address field for CCK
Version:
5.x-2.1
Component:
Miscellaneous
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
11 Jan 2008 at 19:49 UTC
Updated:
23 Jul 2009 at 03:23 UTC
This is totally bizarre.
I only want to use the City and State portions of the Address widget, so in my address field unchecked all the other sub fields.
When I go to submit new content, I get validation errors saying the address and zip code fields are are required.
So I added some code to print out what the required attribute is being set to for the form:
$form[$field['field_name']][0]['street1'] = array(
'#type' => 'textfield',
'#title' => isset($field['field_names_street1']) ? $field['field_names_street1'] : t('Address'),
'#default_value' => isset($items[0]['street1']) ? $items[0]['street1'] : $field['field_defaults_street1'],
'#required' => $field['fielddisplay']['field_display_street1'] == 'field_display_street1' && $field['required'] == TRUE ? TRUE : FALSE,
'#size' => 20,
'#maxlength' => $field['max_length_street1'] ? $field['max_length_street1'] : NULL,
'#prefix' => '<div class="cck-address-street1">',
'#suffix' => '</div>',
);
print "field_display_street1: " . $field['fielddisplay']['field_display_street1'];
print "<br/>" ;
$x = ($field['fielddisplay']['field_display_street1'] == 'field_display_street1') ? TRUE : FALSE;
print "(field_display_street1=='field_display_street1'): " . $x;
print "<br/>" ;
print "required: " . $field['required'];
Look what's get printed:
field_display_street1: 0
(field_display_street1=='field_display_street1'): 1
required: 1
Somehow even though field_display_street1 is not equal to the text 'field_display_street1', it still is evaluating to TRUE!
I'm not a super PHP whiz, but this really doesn't make sense.
Has this been encountered before?
Thanks,
-- Jason
Comments
Comment #1
rconstantine commentedDo me a favor and try changing both the original and your test's == into === and see if that does the trick. Sorry I don't have time to check this out myself right now.
Comment #2
jsm174 commentedThanks! I made the suggested changes and it works fine. I tested both the checked and unchecked settings.
Initially I thought about === but used strcmp. (For some reason === always confuses me.)
Anyway, along with your suggestion, I read that === works pretty much like strcmp in these kind of situations. Plus it keeps the code cleaner.
It looks like it needs to be changed in 11 places:
-- Jason
Comment #3
rconstantine commentedCool. Thanks for that. I personally only tried leaving off the 'Other', 'Country' and 'State' fields, so I didn't even think people wouldn't want to use the other "end" of the address field list.
The third equal sign, IIRC, means that you want the values to be identical, not equivalent; there's no real trick there. Thanks for finding the bug and helping test the solution. I'll review it one more time on my setup before committing the changes to a release.
Comment #4
NewZeal commentedIssue more than 6 months old