Posted by ocamp on December 27, 2012 at 3:11pm
Hi im using drupal 7.
I have a field in a content type.
What I would like is to validate the field using php. If the validation fails I would like the field to be hidden, or say closed.
How can I hide/change the output of the field based on PHP validation?
Thanks for any help
Comments
True validation is used to
True validation is used to accept or reject input values. Values that causes validation errors cause the form to re-display so the user can fix the value. So for normal use, such values would never enter the database. So I am a little unclear of what you are trying to do.
Hi, sorry i didnt mean
Hi,
sorry i didnt mean validate the value of the field.
I mean just compare php values, if it returns true the field displays what is input/what value stored in the database. If the php comparison returns false then I want the field to be hidden and other text to be displayed.
Change node.tpl.php
There is a variable created for each field in a content type. For example if a content type has a field with a machine name of field_foo, then there will be a variable called $field_foo accessible in node.tpl.php.
So in your theme's node.tpl.php you could add something like
if ($field_foo[0]['safe_value'] == 'some_value' {hide($content['field_foo'];
}
Merry Xmas