0

$fs has following data

 $fs = Array
(
    [values] => Array
        (
            [field_1] => Array
                (
                    [und] => Array
                        (
                            [0] => Array
                                (
                                    [target_id] => val_1
                                )

                        )

                )

            [field_download_1] => Array
                (
                    [und] => 1
                )

            [field_download_nid_1] => Array
                (
                    [und] => Array
                        (
                            [0] => Array
                                (
                                    [target_id] => Downloaded_48840
                                )

                        )

                )

            [field_status_1] => Array
                (
                    [und] => 7
                )

            [field_view_1] => Array
                (
                    [und] => 1
                )

            [field_view_nid_1] => Array
                (
                    [und] => Array
                        (
                            [0] => Array
                                (
                                    [target_id] => Viewed_48840
                                )

                        )

                )

            [field_rt] => Array
                (
                    [und] => 0
                )

            [field_date_1] => Array
                (
                    [und] => Array
                        (
                            [0] => Array
                                (
                                    [value] => Array
                                        (
                                            [date] => 11/19/1927
                                        )

                                )

                        )

                )

            [field_date_2] => Array
                (
                    [und] => Array
                        (
                            [0] => Array
                                (
                                    [value] => Array
                                        (
                                            [date] => 17/08/2011
                                            [time] => 20:04
                                        )

                                )

                        )

                )

            [field_date_2] => Array
                (
                    [und] => Array
                        (
                            [0] => Array
                                (
                                    [value] => Array
                                        (
                                            [date] => 18/08/2011
                                            [time] => 08:49
                                        )

                                )

                        )

                )

            [field_text_field_1] => Array
                (
                    [und] => Array
                        (
                            [0] => Array
                                (
                                    [value] => 
text is displayed here 
                                )

                        )

                )
            [nid] => 48840
            [vid] => 48840
            [uid] => 1
            [op] => Report stamp
        )

    [triggering_element] => Array
        (
            [#parents] => Array
                (
                )

        )

)

The drupal_form_submit() is called when submit button is clicked on a form(which is not abc_node_form).
drupal_form_submit('abc_node_form', $fs, $node );
abc_node_form : form_id of content type abc .
$fs : has all the values extracted from the $node.
$node : form_state of the form which has all the values for which the content_type abc needs to be updated.
Also I have checked for form_get_errors(), I dont get any errors but the form node does not get updated.;

4
  • Related: drupal.stackexchange.com/questions/45752/…
    – Mołot
    Commented Oct 16, 2013 at 7:03
  • I have added it in same manner but it still does not upadate the node. Can you please help me out ?
    – harshal
    Commented Oct 16, 2013 at 7:09
  • make sure you are inlcuding module_load_include('inc', 'node', 'node.pages');
    – arpitr
    Commented Oct 16, 2013 at 7:23
  • yes I have included it but still it does not updated whereas node_save() updates the node if used.
    – harshal
    Commented Oct 16, 2013 at 7:23

3 Answers 3

1

Make sure about the parameters you are using

 drupal_form_submit('abc_node_form', $fs, $node );
  • 'abc_node_form'- is the appropriate form id.
  • $fs - current state of the form. Most important is the $form_state['values'] collection .
  • $node - is the old node object, that you will find in $form_state['node'],if using default node creation form.

I am not sure how you are getting $node value,here is small snippet which can be helpful to build $node

  // Before drupal_form_submit()
  $node = node_load($fs['nid']);
  $fs['node'] = $node;
  drupal_form_submit('abc_node_form', $fs, $node );
2
  • 2
    Additionally one needs to ensure that $fs['values']['op'] is set to the value of the submit button on the target form. In this example I think it should be $fs['values']['op'] = t('Save');
    – znerol
    Commented Oct 16, 2013 at 9:39
  • $fs = array() .What all values should $fs have ? Should it have nid,vid,revision etc also along with fs['values']
    – harshal
    Commented Oct 16, 2013 at 10:05
1

As said by @znerol

Additionally one needs to ensure that $fs['values']['op'] is set to the value of the submit button on the target form. In this example I think it should be
$fs['values']['op'] = t('Save');

this solved the problem and node is being updated

1

this was how i submitted an existing node using drupal_form_submit:

$node = node_load($nid);
$fs['build_info']['args'] = array($node);
form_load_include($form_state, 'inc', 'node', 'node.pages');
$form = drupal_build_form('mytype_node_form', $fs);
$fs['node'] = $node;
$fs['values']['op'] = t('Save');
drupal_form_submit('mytype_node_form', $fs, $node);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.