Hi all,
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.
I guess i can do this using "Computed fields". I read and got some clue from this post (http://drupal.org/node/182473 ) but yet i couldnt get this done .
You can see my details in forum post here http://drupal.org/node/466694 . please help me guys.
With regards
Mohan
Hi Mohan, I've read your lines:
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.
and the thread you mentioned on Dupal.org:
You can see my details in forum post here http://drupal.org/node/466694 .
So far, I wasn't able to understand if the logic should be applied at input time or at render time.
I guess i can do this using "Computed fields". I read and got some clue from this post (http://drupal.org/node/182473 ) but yet i couldnt get this done .
Maybe computed fields could make it for input time, but in any case it could be useful if you explain in deeper detail the steps you've already done and report the PHP you're using, so that others can reproduce it and check out what's not working.
If you have to apply the logic only at render time you can achieve it with Contemplates quite easily.
Hope this helps, regards, Francesco
Hi Francesco,
Thanks for your time and the reply. As far as i know, i can refer to a cck field ( in computed field) as $node->field_data[0]['value']; but i am also wondering how to refer a cck field in node body with php input. according to the suggestion given by "Marcus" (http://drupal.org/node/466694), i am trying to use some php code to hide and display a cck field in node body.
Beside this, here is the code i have used for computed field to display and hide a cck field.
$content1 = $node->field_data1[0]['value']; $content2 = $node->field_data2[0]['value']; $t=getdate(); $today=date('D, m/d/Y - H:s',$t[0]); $due_date = $node->field_whatisdate[0]['value']; if ($due_date >= $today){ $node_field[0]['value'] = $content1; }else{ $node_field[0]['value'] = $content2; }
*Display:* $display = $node_field_item['value'];
This is how i tried but no luck. i still have issues. please check with this. Thanks in advance.
With regards Mohan
On Wed, May 20, 2009 at 4:37 PM, Francesco entuland@gmail.com wrote:
Hi Mohan, I've read your lines:
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.
and the thread you mentioned on Dupal.org:
You can see my details in forum post here http://drupal.org/node/466694.
So far, I wasn't able to understand if the logic should be applied at input time or at render time.
I guess i can do this using "Computed fields". I read and got some clue
from
this post (http://drupal.org/node/182473 ) but yet i couldnt get this
done .
Maybe computed fields could make it for input time, but in any case it could be useful if you explain in deeper detail the steps you've already done and report the PHP you're using, so that others can reproduce it and check out what's not working.
If you have to apply the logic only at render time you can achieve it with Contemplates quite easily.
Hope this helps, regards, Francesco -- [ Drupal support list | http://lists.drupal.org/ ]
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
Hi again, a typo to fix and a note I forgot to add:
- a Date field named "due_date"
the above was of course "duedate", as the mentioned code states:
$due_date_timestamp = strtotime($node->field_duedate[0]['value']);
As for the note, you can see that the timestamp is created parsing a string. This means that you are not obliged to use a Date field - a plain text field will be fine - but using the Date module will ensure the date validation in first place.
My code might not work if the string passed to strtotime is not correctly formatted. Be sure to feed it a correct time format.
Have a nice day, Francesco
2009/5/21 Francesco entuland@gmail.com:
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