Hi,
I have been fortunate enough not to have to post a query for over a year now as I have managed to master the majority of what Drupal has to offer however there is one part I just can't seem to get the hang of despite spending the last two days reading everything I can find on entering default values.
Hopefully if someone can help me out here the penny will drop.
I have a CKK content type called 'user_profile' with a text field called 'field_p_first_name'. What I want to do is to populate the default value on another text field called 'field_first_name' on a content type called 'respondent_profile' with the current user's first name. Obviously 'field_p_first_name' holds users first name details.
Each user will only be able to complete one 'user_profile' content type. The user should be able to overwrite the default if required.
I would be thankful for any help on the php I need to enter into the 'default' part of the field formatted as required. Maybe then I could work out what was happening. At the moment i am completely confused and am off to bed now as I can hardly think straight.
Whilst I'm at it is there any decent tutorials on this or do I need to delve into the Drupal Developers section to learn a lot more?
Cheers
Comments
I just did the same thing not
I just did the same thing not too long ago.
The Rules module (and Token I believe) is what you need to work with to accomplish this.
I set it up so that when a new content profile was created and saved, it created a new node and pre-populated some of the fields of this new node with values from the content profile. Way cool.
http://gotdrupal.com/videos/drupal-workflow-automation
This is pretty good overview of the Rules module.
It is what got me going with it.
Hi Dougzilla, Thanks for the
Hi Dougzilla,
Thanks for the reply. I've spent 4 hours tonight with the Rules Module and it certainly looks a very useful module and on the face of it, it should do precisely what I wanted. However. For the life of me I can't get the field value to transfer across. I wonder if you can help a little further.
This is what I have:
Two content types - User Profile and Respondent Profile. 'User Profile' is a Content Profile type and is used in place of the core Profile functionality but is otherwise just a normal node.
'User Profile' has a CCK text field 'field_p_first_name' which is populated. 'Respondent Profile' has a CCK text field 'field_first_name'.
I want the value in 'field_p_first_name' to be entered into 'field_first_name' when the Respondent Profile type is loaded.
So here's what I've done with Rules:
Set a rule up to trigger on 'Respondent Profile node form is being built'.
No conditions.
Action: 'Load Content Profile' - Which makes the CCK fields available.
Action: CCK 'Populate a Field' - And choose field 'field_first_name' which opens the field text box.
Paste the token '[profile_node:field_p_first_name-raw]' into the field text box.
Save.
When I open the Create Content type 'Respondent Profile' the field remains empty. Even when I don't bother with the token and enter a test string 'Test' that will not appear either.
The log says the rule has executed:
Are you able to suggest where I'm going wrong? It all seems pretty simple to me but for some reason I can't get it to work.
Any help would be most appreciated.
Thanks
Drunkencelt
www.dc-website-services.co.uk
Website Design | Hosting | Maintenance | Domains
Also Posted in the Rules
Also Posted in the Rules Issue Queue as a Support request.
http://drupal.org/node/698766
Drunkencelt
www.dc-website-services.co.uk
Website Design | Hosting | Maintenance | Domains
This is rough, but it may help
I am not an expert by any stretch, but I made it do what I needed it to. Hope this helps.
This is what I have been doing.
Make sure that you have the form events turned on @ admin/rules/forms for the form that is the trigger.
On creation of a new node of the type "Family Profile" rules is set up to create a new node of the "Family" type.
The field called "test family" in the new "Family" node gets populated with the value of the field "field_prof_fname" from "Family Profile".
In new triggered rules.
Pick and event --> Event = saving new content
Now the conditions
IF
Condition, content has type --- pick type -- in my case family profile
Do
1/ Action: add new content --> pick node type -- in my case, family node type
2/
a/ Action: CCK populate a field
b/ Content --> new content of type family
Field --> pick your field from the dropdown (this is the field that will get populated)
c/ (This screen shows the receiving field)
Content --> new content of type family
It shows the field that get the data
Now for the tricky part you need to use the "Advanced: Specify the fields value with PHP code" option
This will grab the field value that you specify.
It has to be in the format specified on the bottom of the form
//this code works for me// this grabs the field 'field_prof_fname' from the family node
return array(
0 => array('value' => $node->field_prof_fname[0]['value']),
);
Hi Dougzilla, Many thanks for
Hi Dougzilla,
Many thanks for this. There is obviously something strange going on with my set up. I'm not sure if it's a bug or not.
I've followed your process above and can replicate the creation of a new node but for some reason neither the PHP or token values will show up in the field, however if I enter a string value like 'test' in the field that will show up. If I use a token the field interperates it as a string and displays the token as I entered it and not the result.
I've turned on all the PHP options in 'Permissions' just in case but it shouldn't as I'm using User 1 anyway. Even so it didn't help. For some reason rules does not seem to be recognising the token or the PHP. Token are recognised though if I use them to create the title of the automatically created second node.
Strange behaviour. Guess I need to keep trying different things.
Cheers
Drunkencelt
www.dc-website-services.co.uk
Website Design | Hosting | Maintenance | Domains
Looking at my code above, I
Looking at my code above, I see that my comment was misleading. It should read:
//this code works for me// this grabs the field 'field_prof_fname' from the family profile node
return array(
0 => array('value' => $node->field_prof_fname[0]['value']),
);
I am sure it is not a bug or
I am sure it is not a bug or having to do with permissions.
My description of the process is most likely a bit off.
It sounds like that in your case, it is not referencing the right node to grab the content from.
Take a good look at the dropdowns where you pick the events and the node types to make sure that you have the right one selected.
I do not have a working example of this set up now or I would offer more help.
Good luck with it.
Hi dougzilla, Thanks
Hi dougzilla,
Thanks again.
Yes I understood your comments and understand the principle of what this is trying to do. I have selected the correct type and just to be sure have played around with the others for quite a while. There has to be something not quite right with my set up or something as it looks pretty straight forward. If I get it to work I'll post back here in case someone else is having similar difficulties.
Cheers.
Drunkencelt
www.dc-website-services.co.uk
Website Design | Hosting | Maintenance | Domains
Need Text field which will get value from central place for any
I added a text field to a new content type with some default value.
I created many nodes of this type and all of them had the same default value.
Most of content is different in each node, but only this field has to have the same value.
It is good, but if I will change a default value it will effect only brand new nodes I will create.
Now I have another task. I need some kind of text field which will grab value from central - default location and
when I will change the value in this location, then all nodes will use a new value.
Do you know any solution for it?