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.
Related
Iam very new to Drupal 7 so bear with me. I have created a jQueryUI drag and drop interface with JQueryUI tabs. My problem is i cant find the correct hook to add this custom interface to the admin interface. Like so (mockup) http://onlinemedia.rmcad.edu/sandBox/screenshot/screen-shot.jpg
All the examples I find are using CCK fields. CCK fields are great but they dont have this kind of custom functionality I want or does it?
Any help would very much be appreciated.
J
cck is drupal 6, not 7. to add to the node creation form you could use hook_form_alter or hook_form_ID_alter.
Check the form api documentation to get an idea of how to add stuff to the form object in either of those hooks.
From your mockup I understand you intend to add this drag&drop interface to a content-type.
If that's the case, I'd recommend you to add the appropriate fields first. Those would help storing the data in Drupal way, once the node is saved.
Once you are satisfied with the fields collecting the data you need, create a module and use hook_form_FORM_ID_alter hook to integrate your "interface", the presentation layer by altering those fields.
If you don't want to add CCK/Field components to store your data how about you create your own database table and store your custom data in there?
This approach is a long one but I have used it to great effect on a very big and complex project.
You will need a custom module with an install script which contains the details of your custom database table.
Forgive me but I don't remember the hook for altering a node-edit-form but that is where you input the code which implement your drag-'n'-drop elements.
Then, you could save the settings altogether when the node-edit form is submitted but I think it's probably better to implement some AJAX to save the settings to your custom database table. So, when a component is dropped into it's final resting place, you use AJAX to save that information to the database.
When a user comes back to edit that page, you simply load your custom settings and apply them to the drag-'n'-drop features and their previous configuration(s) would be visible to them.
I do hope that makes sense and it helps you.
I am having trouble finding sources of information or example code for a creating a custom module (or any means) to edit the node edit/insert pages.
I am trying to create a Flickr Integration for a node. The Flickr API is not an issue and i can resolve those, it's the Drupal API issues i could use some help or resources of information on.
Here is what i am trying to achive.
User attempts to add or edit a node
User inserts a keyword into a field and presses a button (Get Photos)
Flickr API returns and displays a few images
User clicks on an image and the URL of the image is then added to an input field
on node save or node update a field such as $node->flickrImage[0][value] is updated with the URL selected in 4.
the variable is the available when ever the node is rendered.
I'm not quite sure how to achieve this - I simply need some example code of modifying the node edit/insert pages and I think I can work the rest out.
Please Help!
Thanks,
Shadi
It looks for me, that you can write own CCK field type, so that you can add this to desired content type and process user's input & work with flickr API.
this way, it's easier to manage this field and control it, plus it will be automatically added to node edit/create forms, node loads, etc.
This article might help http://www.lullabot.com/articles/creating-custom-cck-fields
Second way, is to use hook_form_alter
function module_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'product_node_form') {
//do smth
}
}
In this case, form_id you want to change, will be {content_type}_node_form.
there you can add your field, and process it on
hook_nodeapi
Here is a link for node edit form alter solution ..
http://drupal.org/node/101092
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
I am using the Drupal 6 module Content Profile to allow using a CCK defined type as a user profile which is working well. The issue I have is that I want the first completion of the profile to trigger an action however the user may save the profile without completing it. My thoughts on this is to have a checkbox by the save button which states 'My profile is complete' which the user will select once they are happy with it, and I have another module which creates a trigger by using the node_api hook and checking the type of the node, the action, and the value of this checkbox.
Once this trigger has been raised I don't want that checkbox to appear again however. If I could set the visibility of the checkbox using PHP code that would work as I could write a short script to determine if the completed action has already happenede and if so hide the checkbox. Is there a module that allows this? I haven't been able to find one.
I have also looked at using the same node_api hook to manipulate the profile as it is being displayed however the node just seems to have the values for the fields and not a form object that can be manipulated as I would have expected. IS there a way to programatically manipulate a CCK form?
Thanks
I think hook form alter is what you are after. This can perform alterations to a form before it is rendered.
I would suggest another approach using the Save & Edit module. Set your CCK profile type as "unpublished" by default. Allow users to save it and/or save AND publish it with this module. On publish, use triggers and actions.
This approach is arguably more in keeping with the Drupal way - configuration over customization.
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.