I have created a node type called "nomination" and a field on it called "url_field"

I've been able to prepopulate the title field but can't get anything to go in the URL field. I tried:

http://www.mysite.com/node/add/nomination?edit[url_field]=HelloWorld

without luck.

Once I work out how to do that, my aim is to fill the referring URL into that field. Is that possible only with PrePopulate or do I have to go deeper into the code?

Comments

rjl’s picture

Couldn't you just use drupal's referer_uri() function in your code?

esllou’s picture

could you just give me a pointer as to how I'd use that. I just tried to add it as "Default Value" using php code in a CCK field and I got a world of errors. I'm no PHP guru!!

rjl’s picture

2 things

1. Using referrer_uri()
I'm sorry, when I read created a node type called "nomination" and a field on it called "url_field" I assumed you had created your own node-type module. With version 5.x it is now very easy for anyone to create node-types and extend them with CCK fields. I know... I should never assume... so I appologize. Be that as it may, then you can't of course just use the referrer_uri() function, you would have to create a module to do that, which requires PHP knowledge and Drupal knowledge, so let's take that option off the table for now.

2. Getting your CCK field to prepopulate
I installed the prepopulute module and I too could not get it to work with any of my CCK fields (links, text fields, - none of them could I get to work). The prepolutate read-me doesn't outline how to do it either. There are some issue posts, this one: Prepopulate fails on CCK fields inside a Group is roughly the same problem, and this one: Pre-populate with CCK select boxes seems to offer some hints, after reading it, and several attempts I could get it to work.

Some information that helped me:

  • CCK fields append 'field_' to your natural field name such that if you created a field named 'website' CCK would change it to 'field_website'. If your natural field name had spaces in it, spaces are converted to '_' (underscores) such that if you created a field named 'web site' CCK would change it to 'field_web_site'
  • CCK allows multiple values for a field when that option is checked, the first is 0, the second 1, etc. This transalates your fields to [FIELD_NAME][0], [FIELD_NAME][1], etc. When multiple is not checked, then you just get the first of those: [FIELD_NAME][0].
  • A link field has multiple parts to it (url, title, etc.) even if you've disabled some of them. To reference those you need [FIELD_NAME][0][url], [FIELD_NAME][0][title], etc.
  • CCK allows you to group fields in a fieldset. If you have done that then you need to include the group name at the beginning (note the group name can be found in the admin section for your node type, it will be somehting like 'group_example'. The reference then becomes [GROUP_NAME][FIELD_NAME][0][url], [GROUP_NAME][FIELD_NAME][0][title], etc.

So this was my scenario that I got to work, and I hope it helps you:
I have a "resource" node-type, one of its fields is a CCK link field, I named "resource_url" whick CCK named "field_resource_url" This field is in a group with a few other fields. The name of the group is "group_resource_information" To get the URL to prepopulate with "http://www.example.com/" I used "?edit[group_resource_information][field_resource_url][0][url]=http://www.example.com/"

I'm also going to post the solution part of this along with this issue: Prepopulate fails on CCK fields inside a Group mentioned above.

esllou’s picture

I appreciate the time you've taken to respond here. I am very frustrated that I can't get it to work at all. I even set up the node-type with exactly the same group and field settings without luck.

I'm thinking this is the wrong solution anyway, seeing as you've told me I can't use referrer_uri like this.

Would you know how else I could simply pass info on Page A onto Page B? My idea is for my users to be able to nominate good stories on my site for prizes and I would like to have this type of nomination alongside the usual voting/rating scripts.

rjl’s picture

Sorry, you are having this trouble. I too become very frustrated on occaision with drupal.

I have not tried either of these modules, but both sound like they may be able to do what you want.
Context Links
Custom Links

I would also suggest to keep trying with prepopulate. Take your field out of the group that it is in and give it a try with just
node/add/nodetype?edit[fieldname][0][url]=http://example.com

Looking back at your original post, I am wondering...
Is the field a "link" field created with the "link" module for CCK?
Or is it a regular "text" field that you are using to store the URL value?

To know for sure go to "manage fields" page for the node type. In the "type" column, it should say "link" or "text" If it is "text" then I am guilty of assuming again (sorry). Then you shouldn't need the [url] part and node/add/nodetype?edit[fieldname][0]=http://example.com should work.

for fieldname make sure you are using exactly (case matters too, should be all lower-case) what you see in the "name" column when you are on the "manage fields" page for your nodetype

esllou’s picture

rjl,

here's the deal.

I have a node: nomination
only two fields in it.

Title field, by default
Other is:

Label: url
Name: field_url
Type: Text
not in any groups.

So this should work:

http://www.mysite.com/node/add/nomination?edit[field_url][0]=helloworld

but it doesn't and I can't see why not.

this works:

http://www.mysite.com/node/add/nomination?edit[title]=helloworld

Perfectly! So I know most of that url is right. I've even tried the following:

http://www.mysite.com/node/add/nomination?edit[field_url]=helloworld
http://www.mysite.com/node/add/nomination?edit[field_url][Text]=helloworld
http://www.mysite.com/node/add/nomination?edit[field_url][0][Text]=hello...

I am using:

Drupal 5.1
CCK: 5.x-1.4
PrePopulate: 5.x-1.1

and....I'm getting frustrated! :-)

I will go and have a look at those 2 modules now. Thanks.

rjl’s picture

I feel really bad

I looked at the source code for my rendered form and for my link field named "field_resource_url", this is the html code, it shows the field's name as "field_resource_url[0][url]"

<input type="text" maxlength="255" name="field_resource_url[0][url]" id="edit-field-resource-url-0-url"  size="60" value="" class="form-text" />

On the same form I have a text field for the author of the resource named "field_resource_author", this is the html code, it shows the field's name as "field_resource_author[0][value]"

<input type="text" maxlength="150" name="field_resource_author[0][value]" id="edit-field-resource-author-0-value"  size="60" value="" class="form-text" />

So I guess, I am asking you to try something else, but I would understand if you've given up on me.

http://www.mysite.com/node/add/nomination?edit[field_url][0][value]=hell...

esllou’s picture

hey that worked! Phew....finally.

I had gone into the html source on Friday eve and had seen that, but I must have done it without the [0].

Now, here's the question. How would I get the RIGHT url to be put into that box. I still can't see how I can get someone to click on a "Nominate Story" link and the correct url value already be in the link url, ready to be passed onto the target page's form.

And then I'd have the final problem...where the submitted page/form goes.

Thanks for your help so far.

rjl’s picture

That's great, I knew it had to be something. I hate it when it takes a day to something that should have only taken an hour.

Now that it appears that prepopulate does in fact work on your site...

Your next issue is creating the "nominate story" link. I should ask the question: Why store the URL? It sounds to me that it may be your indicator of which "story" has been nominated? If this is so, why not use a node reference field type instead? Regardless, check out those two modules I noted earlier, to see what options they offer for creating links.

You also mentioned another issue "where the submitted page/form goes" - not exactly sure what you mean. The submission becomes a node of course, but I think you know that. If you mean where does the user go after submitting the form, you can try the Node Go To module for that.

I might also suggest creating a new forum post that asks "How do I..." This current post title doesn't really suggest the advice needed now and I would be worried that others won't be looking at the post and offering other thoughts

esllou’s picture

the problem I have with the node reference type is two-fold.

1. A user will be on a story he or she likes. If they click that "Nominate a Story" link, they will then go to this nomination node. I could have a node reference field on there but this is going to be a huge site, with thousands of nodes. A drop down isn't very user friendly in that situation.

2. It's not intuitive for someone to click a link and then have to fill out a form anyway. Which is why I was looking for a way of someone clicking a link and the URL (or nid) already being in the field...even if only hidden and viewable by mods and admins.

As regards the "where does the submission go", I guess I was looking for a way for the user to be able to submit that nomination form and for it to arrive in an admin's mail box....not exist as a standard node. Is it possible for a user to be given permission to create a nomination node (which they'd need) but not to be able to view them??? that sounds a bit odd....

sorry if I've dragged you into this issue. :-)

rjl’s picture

My question about the text field vs. node reference field was really about me better understanding your situation and not assuming - as I have a track-record of making bad assumptions :-)

There are a number of options available to you in terms of what you want to do.

I would start from the point of defining my specific use-case.
Based on the use-case I would browse thru the modules section, download those that appear to offer the functionality that I need and test them out.

You could set "nominations" node types to not-published or you could use the modr8 module
You could use the notify module to send the email
You said "not exist as a standard node" maybe the webform module would be a better way to go?
You have the link issue, if those modules noted previously don't provide the functionality you need, you can always adjust your themes template files to provide the link, this option requires some PHP and Drupal knowledge though.
Also, if you find a module that does almost what you want it to do, but not exactly, you can post a "feature request" issue with the project.

Ultimately, only you know exactly what it is that you want. It can take a long time to check out all the potential modules, but I think worth it. As an example, you found and reviewed the CCK module and chose a text type field vs. the node reference type field. You wanted an option for pre-filling fields, you found the prepopulate module, reviewed it, had trouble with it, etc. This same process will be used over and over, discovering some things are easy, some difficult, some functionality exists, some does not (or not exactly how you want it), sometimes you will find multiple methods available and will need make a choice (as with the CCK field). I don't mean for it to sound daunting, but Drupal is amazingly rich, and constantly changing, and hopefully worth learning more about.