[support] display/hide a cck text field based on the input cck date field
Francesco
entuland at gmail.com
Thu May 21 10:26:45 UTC 2009
Hi Mohan,
> I'm trying to display/hide a cck field based on the input given in another
> field. My situation is i need to show a cck text field based on the server
> time...if it doesn't matches, I need to display another cck text field.
here is what I've done:
I created a content type with the following:
- a Date field named "due_date"
- a Text field named "answer"
- a Computed field named "computed"
Then I've given this code to the "computed" field:
$answer = $node->field_answer[0]['value'];
$t = getdate();
$today_timestamp = $t[0];
$due_date_timestamp = strtotime($node->field_duedate[0]['value']);
if ($today_timestamp >= $due_date_timestamp){
$node_field[0]['value'] = $answer;
}else{
$node_field[0]['value'] = "The answer will be shown on " . date('D,
m/d/Y - H:s',$due_date_timestamp);
}
As you can see from the code, the "if" statement compares the
timestamps, then returns the answer or a notice about the due date,
depending on the comparison.
Hope this is what you wanted to do - of course you have to hide the
"answer" field from display. The code above could be easily adapted to
display another field instead of that notice.
I don't know how to do the same work inserting the result into the
node's body, I might have a try at it if nobody else has a quick
pointer about the solution to your additional request.
Have fun,
Francesco
More information about the support
mailing list