0

だから私はこのチュートリアルhttp://drupal.org/node/751826に従っています。私は次のコードを取りました:

<?php
function test_myform(&$form_state) {
  // Access log settings:
  $options = array('1' => t('Enabled'), '0' => t('Disabled'));
  $form['access'] = array(
    '#type' => 'fieldset',
    '#title' => t('Access log settings'),
    '#tree' => TRUE,
  );
  $form['access']['log'] = array(
    '#type' => 'radios',
    '#title' => t('Log'),
    '#default_value' =>  variable_get('log', 0),
    '#options' => $options,
    '#description' => t('The log.'),
  );
  $period = drupal_map_assoc(array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800), 'format_interval');
  $form['access']['timer'] = array(
    '#type' => 'select',
    '#title' => t('Discard logs older than'),
    '#default_value' => variable_get('timer', 259200),
    '#options' => $period,
    '#description' => t('The timer.'),
  );
  // Description
  $form['details'] = array(
    '#type' => 'fieldset',
    '#title' => t('Details'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['details']['description'] = array(
    '#type' => 'textarea',
    '#title' => t('Describe it'),
    '#default_value' =>  variable_get('description', ''),
    '#cols' => 60,
    '#rows' => 5,
    '#description' => t('Log description.'),
  );
  $form['details']['admin'] = array(
    '#type' => 'checkbox',
    '#title' => t('Only admin can view'),
    '#default_value' => variable_get('admin', 0),
  );
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#size' => 30,
    '#maxlength' => 64,
    '#description' => t('Enter the name for this group of settings'),
  );
  $form['hidden'] = array('#type' => 'value', '#value' => 'is_it_here');
  $form['submit'] = array('#type' => 'submit', '#value' => t('Save'));
  return $form;
}

function test_page() {
  return drupal_get_form('test_myform');
}
?>

このコードをテキスト フィールドに貼り付けました。最後に、php の終了タグの前に、関数 test_page を次のように呼び出しました。

test_page();

保存後に次のエラーが表示されます。

    Warning: Parameter 1 to test_myform() expected to be a reference, value given in drupal_retrieve_form() (line 785 of /var/www/html/includes/form.inc).
    Warning: Parameter 1 to test_myform() expected to be a reference, value given in drupal_retrieve_form() (line 785 of /var/www/html/includes/form.inc).

理由がわかりません。基本的に私がやろうとしているのは、Webフォームを作成してサーバーにローカルに保存することです。Drupal Form API を使用する以外に何かアイデアがありましたら、ぜひお寄せください。

どんな助けでも大歓迎です。

4

1 に答える 1

4

test_myform() 関数の引数を次のように変更してみてください

function test_myform($form, &$form_state) {
  ...
}

それはそれをしますか?


コメントの後に回答に追加:

関数をどこでどのように呼び出しているのかわからないので、あまり役に立ちません。その test_page() 関数を取り除き、メニュー項目から drupal フォームを呼び出してみませんか。

したがって、モジュールには、次のメニュー フックを含めるだけです。

 /** 
 * Implementation of hook_menu
 */
 function YOUR_MODULE_menu() {

 $items['test/page'] = array(
    'type' => MENU_CALLBACK,
    'title' => t('Your page title'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('test_myform'),
    'access arguments' => array('view published content'),
 );

 return($items);

}

テストするには、1) モジュールを有効にする、2) すべてのキャッシュをフラッシュしてメニューを再構築する、3) そのメニュー項目を置き換えるものに移動する、この例では www.yoursite.com/test /page または localhost/test/page. メニューからフォーム機能を呼び出す方が良いと思います。

それは動作しますか?

于 2012-05-16T16:45:10.800 に答える