Jonathan
Jonathan

Reputation: 54

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

Upvotes: 3

Views: 1121

Answers (3)

Igor Rodinov
Igor Rodinov

Reputation: 471

use form_set_value(); function on form validation.

Upvotes: 0

Erik Ahlswede
Erik Ahlswede

Reputation: 2155

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

Upvotes: 1

Sid Kshatriya
Sid Kshatriya

Reputation: 5015

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.

Upvotes: 2

Related Questions