0

我正在使用 drupal_execute 以编程方式保存节点,并且在大多数情况下,它工作正常,除非涉及多值字段。

发布的是这个(我只包括不工作的部分):

[alt] => Array
        (
            [0] => Array
                (
                    [name] => Sam I. Am
                    [phone] => (650) 5553131
                )

            [1] => Array
                (
                    [name] => The Lorax
                    [phone] => 6505553344
                )

            [2] => Array
                (
                    [name] => 
                    [phone] => 
                )

        )

当我设置 $form_state['values'] 时,我正在使用:

for($a = 0; $a < count($_REQUEST['alt']); $a++) {
        $form_state['values']['field_alternativename'][$a]['value'] = check_plain($_REQUEST['alt'][$a]['name']);
        $form_state['values']['field_alternativephone'][$a]['value'] = format_phone($_REQUEST['alt'][$a]['phone']);
    }

并保存节点:

drupal_execute('info_node_form', $form_state, $node);

作为测试,为了确保我引用了适当的字段,我使用 node/X/edit 编辑了一个现有节点,并在提交时打印出 $form_state['values'] 。这是它打印出来的:

//output of print '<pre>'; print_r($form_state['values']); print '</pre>';
    [field_alternativename] => Array
        (
            [0] => Array
                (
                    [value] => Sam I. Am
                    [_error_element] => group_alternative_contacts][0][field_alternativename][value
                    [_weight] => 0
                    [_remove] => 0
                )

            [1] => Array
                (
                    [value] => The Lorax
                    [_error_element] => group_alternative_contacts][1][field_alternativename][value
                    [_weight] => 1
                    [_remove] => 0
                )

        )

    [field_alternativephone] => Array
        (
            [0] => Array
                (
                    [value] => (650) 5553131
                    [_error_element] => group_alternative_contacts][0][field_alternativephone][value
                    [_weight] => 0
                    [_remove] => 0
                )

            [1] => Array
                (
                    [value] => (650) 5553344
                    [_error_element] => group_alternative_contacts][1][field_alternativephone][value
                    [_weight] => 1
                    [_remove] => 0
                )

        )

所以,我不明白为什么它没有被保存......我没有设置增量,但我认为我不必这样做?在mysql中,数据存储为:

mysql> select * from content_field_alternativename ;
+-------+-------+-------+-----------------------------+
| vid   | nid   | delta | field_alternativename_value |
+-------+-------+-------+-----------------------------+
| 22433 | 22433 |     0 | Sam I. Am                   |
+-------+-------+-------+-----------------------------+

mysql> select * from content_field_alternativephone;
+-------+-------+-------+------------------------------+
| vid   | nid   | delta | field_alternativephone_value |
+-------+-------+-------+------------------------------+
| 22433 | 22433 |     0 | (650) 5553131                |
+-------+-------+-------+------------------------------+
4

1 回答 1

0

增量是 cck 存储多个值的方式。nid x, vid x, delta 0 是多值字段中的第一个 nid x, vid x, delta 1 是第二个等等。它是必需的,因此如果您将增量添加到您的多值中,它应该可以工作。

于 2011-02-23T18:23:28.017 回答