Can CCK take care of my fields for a programatically defined node type in drupal? - drupal

Does the CCK api allow me to create a node type, from a custom module, with a bunch of fields that use CCK to store their state? If so can these fields be locked so that users may not alter them, but still allow the user to add more fields to the node type?
Thanks

I think the answer to your first question is "yes" (for Drupal 6, at least, which has elements of the CCK integrated into Drupal Core). I believe the Amazon module does this sort of thing, albeit it with just one field.
I don't think the idea in your second request is achievable, though. This would seem to require field-level permissions' control whilst Drupal only supports module-level permissions' control.

You could add validation code in the GUI which restricts CCK fields being interfered with on your content type. This would not prevent another module getting in there with an axe, though.
You could add checks which restore your preferred CCK settings whenever they detect some unwanted changes.

Related

Drupal 6.x Add More Module - No end to adding more

Simple question for all of you here dealing with Drupal 6.x...
With Drupal's Add More module, is there a way to configure my webform so that there is no limit on how many of a specific fields I can add more of?
Please see my image for example:
For example, I'd like to enable the user to add as many titles as they would like. Is that doable?
Unfortunately, it's not currently possible to add unlimited "add another" functionality with webforms. And if this functionality does become a reality someday, I doubt it will be backported to the Drupal 6 version of the module. From the webform modules author (quicksketch):
there is no progress on this subject. The ability to support multiple
values requires a tremendous amount of re-architecting, including
changes to the way CSVs are generated, analysis, the database
structure, and the UI (both for administrators and users). I wouldn't
expect this feature to be added any time soon.
See this thread for more information:
http://drupal.org/node/354381
I would suggest using a node and the CCK module plus rules and views to collect this information.
Assumptions:
Anonymous users can fill out the current form
You need some way of retrieving the data that is submitted
Regular users of the site should not be able to view submissions
Very loose directions:
Create a content type and add all of the fields that your current webform contains to it. CCK has the ability to store unlimited values out of the box. On the field settings page, inside the Global Settings fieldset, select "Unlimited" for the "Number of Values" field.
Give anonymous users permission to Create [your-new-content-type] Content on the Role Permissions page.
Using the Rules module, create a new triggered rule that fires on "Content is about to be viewed" with an condition "Content has type [your-new-content-type]" and an action of redirect to homepage (or a custom error page that you created). (Note: this is a bit of a performance hit. There are better ways to restrict access to this content type, but for the sake of this tutorial, this was the easiest to explain)
Using the Views module, create a new view with Style set to Table. Add each of the fields in [your-new-content-type] in the fields section. Under "Access" choose "role" and select the role that is assigned to your user. Add a "page" display, give it a Path and save. This is the page you will use to view submissions.
Optional:
Use the Rules module to send yourself (or the submitter) an email when a node of [your-new-content-type] is created.

drupal6 taxonomy cache, dropdown arrays & webform vs cck questions

1.is taxonomy do caching ? i do a form that user needs to fill his personal infomation and that include a street name, i wonder how to do it, in taxonomy or in cck text field... what is better?
what is the best way to do a form dropdown options of known-non changing options? like choose color:
red,green,blue.orange,gray ... should i use function and call to array? variable_set/get()? taxonomy vocab?
if i do a form for user that will not send to email its just need to add a node or stuff like that, is webform is a better alternative to the cck module?
taxonomy does no caching afaik. To have adress etc info for user i 'd use profile module in core. (you use d6 or d7?) ,
to 1. simple list of non-chaning option which does not need to maintained elsewhere (db/file) you use cck text field and provide values to choose from. Of course for many values, a cck taxonomy field is nice , because there are good import modules (taxonomy_csv and _xml)
question 2 i find hard to understand, pls elaborate a bit
Taxonomy isn't cached. It is also not really the best choice for entering addresses, CCK is perfect for that. If this data isn't going to be content Webform is ever perfecter :)
The benefit of Core+CCK for form based data collection is you can make nodes out of it, which means you can do anything that you would do with a node to the data you collect. Query, Display, Rules on it, whatever.
The advantage to Webform...is that that it's not turned into a node, as such it's more specialized for collection of information such as surveys, questionnaires, contact forms, etc and there are plenty of integration modules for webform to help you see/use your data in cool ways.
Re your questions:
1) CCK Text/Select - OR - the equivalent in Webform
2) Core & CCK, you cannot add site content with Webform
Cheers

How to create a custom form in drupal

I need help on how to create a 'custom form' using the same fields provided by cck.
Drupal gives you the ability to add fields to 'nodes' and how to theme their output. But I would like to be able to post a data from my own form (that pops-up) and sends data to the drupal database using the same drupal cck.
How do I access the specific form inputs to add data to my content types ? because the default form is kind of 'ugly' and loads on different page(without ajax).
Help would be much appreciated
There are several routes you could go down.
The easier option is to use the Webforms module. While this gives you similar fields to cck, they are not exactly the same, and if you have a module that implements a specific cck field type, it won't be available to webforms.
The second choice is to write your own module using the forms api. This can mean a lot of learning, add it takes time to get up to speed, but ultimately you have total control over how your form will look and behave. The forms api doesn't give you exactly the same fields, but all the tools are there to create them. Sometimes you need to hack open a module to find out haw a specific field is implemented.
A third option would be to use cck itself. You could create a content type and add the field types you want on your form. You would them give users permission to create but not view or edit the content type. The form submissions would them be nodes on your website. This would make me slightly nervous, so make sure all your permissions are correct!
The second part of your question: you can use a theme file to override the appearance of most forms and make them pretty.
James

Changing the value of a field in a Drupal form

I've created a hook submit function for my Drupal node edit form. I'd like to change the value of a CCK field (not in the form) for that specific node within the sumbit handler.
I've tried setting the field as hidden and applying a value to it, but this didn't work.
Could anyone suggest a way to do this?
Thanks,
Jonathan
I think you're probably over complicating things. If all you want to do is change the value of a CCK field on Node save (perhaps based on certain conditions) you're probably better off using the Rules module ( http://drupal.org/project/rules ). There are plenty of videos and resources on the internet on the Rules module.
Also if you want to hide a particular CCK field you can use the Content Permissions module that is bundled with the CCK module. You can deny the user edit access on the CCK field but grant view access.
Instead of adding a submit function to an edit for, why don't you use hook_nodeapi and perform your logic when the $op = 'presave'? This way you don't need a heavy module like rules, but can still alter the values on node submission.
EDIT: Take a look at hook_nodeapi()
use form_set_value(); function on form validation.

How to store user's first-name and last-names in Drupal?

I can not see a first-name or full name field in Drupal's create/edit user form. I am using Drupal 6. How do I store a user's full name in it?
You will need to enable the Profile module for that. This module lets you add fields to users.
See information about the module in the handbook, and some nice instructions here (under "Adding special properties to user profiles").
Drupal supports fully configurable profiles. Turn on the module (it's in core) and navigate to /admin/user/profile to add/edit fields.
Use Drupal's built-in profile module.
I realize that everyone's suggesting the profile module, and I agree that that will work fine on small enough sites, if you don't have too many user profile fields and not too many users... but it can be a hog on larger sites.
I'd also point out the Content Profile module, which allows you to create a node type and use it to extend the user's information that way, which also has the advantage of giving you the width and breadth of CCK for creating fields, instead of being stuck with profile's limited selection.

Resources