How to modify the Node Edit or Insert Form in Drupal - drupal

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

Related

Create moderation for form data

I want to add moderation logic for a form which has name, mail and comment. Now when anyone fills the form and clicks "submit" it should directly be posted to the page. I want to send the content to "admin" and to be published after the content is reviewed. How can I achieve this in Drupal? I'm using Drupal 7.2.
There are many ways to achieve what you want. I guess you are looking for a site-builder approach.
Then you may have a look at the Webform module. Webform lets you build forms and define e-mail addresses to where the submitted data should be send to.
Then there is the Rules module with which you can define a rule that on every form submission automatically a (initially unpublished) node is being created populated with the form values.
And finally you may provide a list of all unpublished nodes built with Views. Maybe you already provide a button "publish" next to each node in the list that triggers the node publication.
Alternatively you may also have a look at moderation modules like Workbench Moderation.
Or have a look at the Flag module which is pretty useful for flagging content according some logic and/or button clicks. For example you can add a flag: approved.

Looking for ideas to implement an anonymous Suggestion Box in Drupal

I have a need to allow authenticated users to create content in Drupal anonymously. Ideally something like a Suggestion Box. The suggestion should have no fingerprint of who submitted it and ideally it should be submitted but not published until it is reviewed and approved.
Looking at the contact form and other modules, I haven't been able to get a clear direction on how to do this. Ideally I would think that at submission, I'd like to override the Authored By field and set this to anonymous. Is this the right direction or can I create a simple form that would be emailed to someone without ever creating a node?
I would suggest just creating a form using webform module.
If you don't want a node, just create a simple php form that sends a mail() on completion. You will need to enable the PHP filter and then just create a page with the PHP form in the content area.
If you wanted a node, you could create a custom content type called suggestions and then use a custom module to remove the author tag using hook_form_alter.
function uofm_usertasks_form_alter(&$form, &$form_state, $form_id) {
switch($form_id)
{
case 'suggestion_node_form':
$form['authored']['name']['#access'] = FALSE; // not sure if this is the right item in the form or not
break;
}
}

Drupal views & to do list

Wondered if anyone can tell me whether the following is possible within views.
I have installed To do module - http://drupal.org/project/to_do
I then created my own view which lists all the tasks created in a particular Organic Group, which works lovely.
One of the fields ive added as the to do button field which gives the user the ability to mark a task as finshed from the view listing.
the problem I have is that all users part of that group can see that buton & has the ability to mark the task as finished.
Is there a way I can use views to only show that button if the current logged in user is the author of that node( to do task).
Views have different templates. In one of them all the fields are being printed. You could in that template make a check if the user is the author and then only print the todo field.
You cam click the theme information link inside the view to get a list of templates that's used and what you could call a custom template for views to use it.
This will only show content the user created. It's a pretty simple argument

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.

Drupal CCK Field Level Visibility

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.

Resources