I am writing a module whereby I use form_alter to generate a custom form for a CCK type. I am trying to figure out how to change CCK field attributes for the form - say using form_alter. There's a post that describes how to play around with the #disabled attribute (http://drupal.org/node/336355 and http://drupal.org/node/300705#comment-985105), but I cannot use it to alter any other attributes.
In particular I'm trying to work out how to set #default_value - so that I can have a form, linked to a CCK type, with a field that takes a URL, a 'lookup' button which has an action associated with it whereby it goes off to the URL, scrapes information and then populates various fields on the form - by setting the default values of the fields and then sets form_rebuild to true. I can do this with the non-cck fields, but have gotten stuck on how to do this for CCK fields....
After many many hours going around in circles, help would be appreciated ALOT!!
thanks
Comments
Here's some of the code I'm
Here's some of the code I'm currently working with:
I also get these drupal error messages, but i think that's a separate issue:
and the field_kg_url doesn't have any default value when I load the form.....I tried setting all the places in the element I could see a value being held.....also form_state seems to be empty? is that ok?
help much obliged!!!!!!
Alter #default_value directly from hook_form_alter()
Alter #default_value directly from hook_form_alter() as in this example, should work. Also, make sure your module is loaded after CCK and maybe also after fielgroup by altering the weight of your module in the {system} table.
Use
print_r($form['field_myfield']);to figure out the structure of the form element that you wish to modify. Not all fields have the same format.Doubt is the beginning, not the end of wisdom.
The error in #pre_render
If you ever need to use #pre_render, be sure to use the correct prototype.
http://api.drupal.org/api/function/drupal_render/6
Doubt is the beginning, not the end of wisdom.