0

Webフォームと関連コンポーネントを正常に作成するこの素晴らしいドキュメントに従いました。

新しいウェブフォームを作成するのではなく、既存のウェブフォームで機能するようにコードを調整しようとしています。私のコードは次のとおりです。

$nid = 12;

  $node = node_load(12);

  // Create the webform components.

  $components = array(

    array(

    'name' => 'Gender',

    'form_key' => 'gender',

    'type' => 'select',

    'mandatory' => 1,

    'weight' => 0,

    'pid' => 0,

    'extra' => array(

      'title_display' => 'inline',

      'private' => 0,

      'items' => "Mrs|Mrs\nMiss|Miss\nMr|Mr",

      'aslist' => 1,

    ),

  ),

  );

  // Setup notification email.

  $emails = array(

    array(

      'email' => 'somebody@example.tld',

      'subject' => 'default',

      'from_name' => 'default',

      'from_address' => 'default',

      'template' => 'default',

      'excluded_components' => array(),

    ),

  );

  // Attach the webform to the node.

  $node->webform = array(

    'confirmation' => '',

    'confirmation_format' => NULL,

    'redirect_url' => '<confirmation>',

    'status' => '1',

    'block' => '0',

    'teaser' => '0',

    'allow_draft' => '0',

    'auto_save' => '0',

    'submit_notice' => '1',

    'submit_text' => '',

    'submit_limit' => '-1', // User can submit more than once.

    'submit_interval' => '-1',

    'total_submit_limit' => '-1',

    'total_submit_interval' => '-1',

    'record_exists' => TRUE,

    'roles' => array(

      0 => '1', // Anonymous user can submit this webform.

    ),

    'emails' => $emails,

    'components' => $components,

  );

  // Save the node.

  node_save($node);

コードを実行しようとすると、次のエラーが発生します。

エラー メッセージ SQLSTATE[23000]: 整合性制約違反: 1048 列 'nid' を null にすることはできません

4

1 に答える 1

2

最初に $node の利用可能なすべての値を出力してみてください。

echo "<pre>";
print_r($node);
echo "</pre>"'
exit;

値が得られているかどうかを確認してください$node[nid]

于 2013-11-11T12:47:52.767 に答える