2

I wanted to associate a file to a node. so far so good. create a cck type file, and the problem was solved. but I can not do this, I do not want the user to choose the file. the file in question is already in the system. I have tried to place the file as # default_value field and hide it with the hook_form_FORM_ID_alter, but failed.

function my_module_form_node_form_alter(&$form, $form_state, $form_id) {
    if(isset($form['type']) && isset($form['#node'])) {
        $type = $form['#node']->type;

        if(stripos($type, 'node-type') === FALSE)
            return;

        switch($type) :
            case 'node-type_xyz':
                $fid = arg(3);
                $file = file_load($fid);

                // make a cck field_invoice a hidden field
                $form['field_invoice']['#prefix'] = '<div style="display:none;">';
                $form['field_invoice']['#suffix'] = '</div>';

                $form['field_company']['und'][0]['value']['#default_value'] = 'ABC';
                $form['field_account_number']['und'][0]['value']['#default_value'] = '09879';
                break;
        endswitch;
    }
}

anyone have any suggestions?

Miguel Borges
  • 7,549
  • 8
  • 39
  • 57

1 Answers1

0

Don't use #prefix and #suffix to hide it. Instead, set #access to false - that way, people can't fiddle with the form. You can set the value in hook_nodeapi or a submit function, or set the type to 'value' and the #value to your file.

Sacha Chua
  • 581
  • 7
  • 6