Drupal问题 - 使用drupal_execute进行多值字段?

时间:2011-02-23 02:11:47

标签: drupal execute

我正在使用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                |
+-------+-------+-------+------------------------------+

1 个答案:

答案 0 :(得分:0)

delta是cck如何存储多个值的方式。 nid x,vid x,delta 0是多值字段nid x中的第一个,vid x,delta 1是第二个等等。这是必需的,所以如果你为你的多值添​​加增量它应该有效。

相关问题