Hi,

I upgraded from CCK rc6 to rc7 and am now getting the above Fatal Error in code where previously I didn't. It is happening in a node_save() function that is run in a custom module. Unfortunately I didn't backup my db before the upgrade so now I am stuck.

Line 1134 is this: unset($items[$field['field_name'] .'_add_more']);

The content type uses text, node reference and decimal fields. I don't use any fields offering multiple options.

I've tried using the latest development snapshot and cleared the cache countless times.

Many thanks for any help

Comments

NewZeal’s picture

Status: Active » Fixed

Problem solved. It was my coding. I replaced a field item with a string instead of an array.

I will have to say though that I have succeeded in creating a form that enables me to create/update a content type and add to several other content types all in the one form using drupal_retrieve_form(), drupal_prepare_forum(), node_submit() and node_save() and filtering out the unwanted form tags. All praise to Drupal functionality. I am very impressed. Go Drupal!

If anyone is interested the error was caused by feeding incorrect variables into node_save. This works: $form_state['values']['title'], but any CCK fields have to be of the form $form_state['values']['field_fieldname']['#value'][0]['value'] or $form_state['values']['field_fieldname']['#value'][0]['nid'] and not $form_state['values']['field_fieldname']. Using the latter was causing the error. Then you can safely do this:

$node = node_submit($form_state['values']);
node_save($node);

and all the work is done for you!

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

igor.stirbu’s picture

Hello,

I used your tip and the source from openid module [1] to implement
similar scheme but I cannot make drupal_retrieve_form() to work.
I have a custom type called 'note' created with CCK. I make the call
drupal_retrieve_form('note_node_form', $form_state); where
$form_state is filled with data. Here is the error I get:

warning: call_user_func_array() [function.call-user-func-array]: First
argument is expected to be a valid callback, 'node_form' was given
in ..../includes/form.inc on line 366.

What am I doing differently?

[1] http://api.drupal.org/api/file/modules/openid/openid.module/6/source look for openid_authentication()

Drupal: 6.6
CCK: 6.x-2.0-rc10

igor.stirbu’s picture

I've fixed that by including node.pages.inc.
module_load_include('inc', 'node', 'node.pages');

igor.stirbu’s picture

In case someone is interested, I managed to acces cck fields in the following form:
$form_state['values']['field_fieldname'][0]['value'] = 'yourvalue';

NewZeal’s picture

How you access a CCK field depends entirely upon what widget you used to create the field in the user Interface. Usually a print_r($form_state['values']['field_fieldname'], true); will let you know.

jday’s picture

I am trying to set the default values of two cck fields in a node form with hook_form_alter but I get the:

Fatal error: Cannot unset string offsets in .../sites/all/modules/cck/content.module on line 1248
which is in fact: unset($items[$field['field_name'] .'_add_more']);

I would like the user to be able to enter different values if they want but pre-fill them for most uses, here is my code:

function kruse_form_alter(&$form, $form_state, $form_id) {
    
    switch ($form_id) {
      // alter the create new showing form
      case 'showing_node_form':
        // prefill values from listing page.
        $mls=check_plain($_POST['mls']);
        $address = check_plain($_POST['address']);
        $photo = '<div class="photo rt"><img src="'.$base_url.'/'.$_POST['photo'].'" width ="200" height ="150" /></div>';
        drupal_set_title(check_plain('Request a Showing'));
        $form['field_mls'] = array(
             '#title' => t('MLS'),
             '#type' => 'textfield',
             '#default_value' => $mls,
             '#prefix' => $photo
        );
        $form['field_showingaddress'] = array(
             '#title' => t('Address'),
             '#type' => 'textfield',
             '#default_value' => $address
        );
        break;
   }
}
jday’s picture

SOLVED:Thanks to the Wisconsin Drupal Meetup group for figuring this out, to set the default value of a cck text field with hook_form_alter, it needs to be written this way:

$form['field_mytextfield'][0]['#default_value']['value'] = 'myvalue';

tetramentis’s picture

New Zeal - thanks a lot for the solution, just had the same error after accidentally assigning string to a CCK text field.

ecksley’s picture

Thanks jDay. That solved my issue. I was trying to hide a field on the node form.

$form['field_name'][0]['#type'] = 'hidden';