Posted by Antinoo on March 6, 2009 at 4:25pm
Hi.
Does there exist a tutorial about the CCK Node Reference fields?
I've created two content types, Father and Son. A Father can have many Sons.
I've added a new Node (Father) Reference field to Son.
I've also added an "Add new Son" link (node/add/son?field_father=123) when the user is on a Father-node page.
Now, I don't know how to autocomplete that Node Reference field with the nid of the Father node.
Could anyone help me?
I'll write a tutorial if it doesn't exist and I succeed to make this work.
Thanks anyway, Giovanni
Comments
About the "autocomplete" field...
When I say "autocomplete", I'm not thinking to the "classical" CCK autocomplete field, but to an hidden field which is filled automatically, without any user input.
Do I need to use hook_form_alter() in order to hide the field and fill it with the Father nid?
Is there no way to make this common work without writing a custom module?
Any tutorial?
hidden field
Antino,
Did you use the hook_form_alter() to hide the field or did you set the CCK permissions so that the end user cannot view the node reference field?
For the moment, I've filled
For the moment, I've filled the CCK field using the [PHP Code] Default Value, and hid it only via CSS.
However, since I want to validate the submitted form - a field hid via CSS can still be modified by a malicious user - to check if the submitted Father nid is actually a node of type 'father', I was going to create a custom module. This means that I'll use the hook_form_alter() to fill the field, and to hide it. The need to validate is another reason for me to use the Node Reference URL Widget module as kswan suggested.
Giovanni
ps. I haven't used CCK permissions to view the field, because I've set the field to be required, and if a user can't view/edit it, she can by-pass the required constrain if I don't fill the field using a custom module. I don't like this behaviour, that's why I've opened an issue here to see if it's intended or not.
I've solved creating a CCK
I've solved creating a CCK Integer field, using the prepopulate module and hiding the field on the form.
However, I don't like the URL that the prepopulate module needs, so I'll try to write a custom module that will handle a prettier URL (eg.
node/add/son/[father->nid]).Thanks anyway.
Node Reference URL Widget
Antinoo,
I was just looking at the Node Reference URL Widget (http://drupal.org/project/nodereference_url). I think it is exactly what you are looking for.
Yeah, it was right what I
Yeah, it was right what I needed!
I had already solved the problem using the
node/add/son/[father->nid]url, and that widget is working fine with the same url, too, so I'll see if it's better to use it (tested code).However, next time I'll look deeper into the modules list and/or will wait some days after I've posted a question to the Drupal community. ;-)
Thank you!
I am glad I could help. I
I am glad I could help. I wouldn't have known except I was searching drupalmodules.com for a different type nodereference module.
The last famous words... :-)
When I go to admin/content/node-type/son it says:
To create a new Son, a referenced piece of content must be specified in the link you followed. And then:The requested page could not be found.I've had to delete the field, and opened a new issue here.
{double}
{double}