views:

29

answers:

3

Hello,

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

+1  A: 

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.

Sid NoParrots
I did something very similar with Node Reference CCK fields. I also used Content Permissions to restrict edit access (which hides the field from the form) and then set the fields value in code. There may be some helpful information in that question... http://stackoverflow.com/q/3764156/318158
Chaulky
A: 

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()

Erik Ahlswede
Thanks very much for this, is there anyway to cancel the node save at a certain point if some criteria are met?
Jonathan
Figured it out. Used hook_nodeapi using the op='presave' and also used op='validate' to check the criteria then form_set_error() to cancel the form processing.
Jonathan
A: 

use form_set_value(); function on form validation

Igor Rodinov

related questions