In the broadest sense I am trying to figure out how to have a CCK field change values based on the value of another CCK field.
Specifically, I am interested in setting one date field, and having the remaining 4 date fields update on the fly. The user should never have to touch the other 4 and they could be hidden if necessary.
The setup is such that each node represents a new hire, and the primary date field represents the hire date. The other four fields represent specific events pertinent to the employee records (such as review dates, raise dates, etc.). I figured something could be possible with computed fields, but would not know where to begin on that one. Also, if this can be done using a datefield it would behave much better with calendars.
Any ideas welcome, and I can handle a fair bit of coding so don't be bashful.
Thanks.
Comments
I'd suggest looking at the
I'd suggest looking at the rules module. It definitely can do this triggered on saving a new node of a specific type.
I have looked into both of
I have looked into both of these suggestions, as I am using Rules and Conditional fields elsewhere in my site. Unfortunately Rules does not appear to be able to modify a date field, and conditional fields can only control the visibility of the field and not it's actual content.
Any other ideas out there?
On the plus side, I have added a few new rules to make things go easier on my site.
It can modify a date field,
It can modify a date field, but sadly I've had to use a snippet of PHP to achieve it. Example:
$now = date('Y-m-d'). 'T00:00:00';
return array(0 => array('value' => $now));
I think this is going to be
I think this is going to be how I have to do it as conditional fields does not address this issue.
Can you give me any more insight into where that snippet resides?
I have set up a rule and didn't get much farther.
I need to take the date of one field and add 5 weeks to it. Any suggestions?
You need to have the PHP
You need to have the PHP filter module on. (I'd suggest not allowing it as an input format.)
When editing the populate field value rule, there's a fieldset called "Advanced: Specify the fields value with PHP code"
With the PHP filter on, you'll see some information about the variables that are available. Usually the node that you're working in will be a variable such as $node. If you've ever used PHP to return field values such as $node->field_name[0]['value'] - that's what you would be doing essentially here. If you install the devel module, you can get a better idea of the values available in your node object.
Dates fields have an internal structure
My dates were formatted as 'dd/mm/yyyy' but setting the value in this format didn't work. Dates are sensibly expected in a canonical format:
This gave me what I wanted:
Of course you can change the relative time of 366 to anything. You could use time() to get a current timestamp instead of strtotime.
And you could do some calculation if you have access to $node as a variable. Not tested, but in that case I'd expect to see something like
for a date ten days after the value in the birthdate. (The second field of the date function takes a timestamp, which is stored in seconds, and there are 24 hours * 60 minutes/hour * 60 seconds/minute = 86400 seconds in a day).
php not using field value to start from but 01/01/1970
I have the same problem: need to have a hidden field populated with the date of an existing datefield +1 day.
So I have a cck field "datema" in which the end user has to enter the date of a monday. I then have another date field "datedi" and a rule containing the following elements:
- ON event Content is going to be saved
- IF Saved content is Rooster week 5
- DO Populate saved content's field 'field_datedi'
In the last action (Populate saved content's field 'field_datedi') I have entered the following code (based upon the comment above) under "Advanced: Specify the fields value with PHP code":
return array( 0 => array('value' => date('Y-m-d', $node->field_datema[0]['timestamp'] + 1 * 86400)));When I create a new node of the type "Rooster week 5", enter a value in the field datema and save it, the result I get for the field datedi is 02/01/1970. Instead of adding 1 day to the value of datema, it adds 1 day to a given start date of 01/01/1970!
How can I solve this? What php code can I enter in order to populate my field datedi with the correct date?
This might be useful
This might be useful http://drupal.org/project/conditional_fields
--------------------------------------------
Konordo Ltd
http://www.konordo.com