Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用drupal_get_form()传递参数_Drupal_Drupal 6_Drupal Modules - Fatal编程技术网

使用drupal_get_form()传递参数

使用drupal_get_form()传递参数,drupal,drupal-6,drupal-modules,Drupal,Drupal 6,Drupal Modules,这是我使用hook定制的模块 假设如果我想将参数传递给custom1\u default\u form函数调用,我应该如何传递参数 <?php function custom1_block($op,$delta=0){ if($op=='list'){ $block = array(); $block[0]['info']=t('hello world'); return $block; }else if($op=='vie

这是我使用hook定制的模块

假设如果我想将参数传递给custom1\u default\u form函数调用,我应该如何传递参数

<?php

function custom1_block($op,$delta=0){
    if($op=='list'){
        $block = array();
        $block[0]['info']=t('hello world');
        return $block;
    }else if($op=='view'){
        $block_content = '<p>THIS IS MY FIRST BLOCK</p>';
        $block['subject'] = 'HELLO WORLD';
        $block['content'] =drupal_get_form('custom1_default_form');
        return $block;      
    }  
}

function custom1_default_form () {
  $form = array();
    $form['nusoap_urls']['txt_name']  =
    array('#type' => 'textfield',
          '#title' => t('Please enter your name'),
          '#default_value' => variable_get('webservice_user_url',''),
          '#maxlength' => '40',
          '#size' => '20',
         // '#description' => t('<br />Root directory used to present the filebrowser user interface.')

          );
     $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Save Details'),
      );          
        return $form;    
  }

  function custom1_default_form_validate (&$form, &$form_state) {

    if(($form_state['values']['txt_name']) == '') {
        form_set_error('user_webservice', t('Enter a name'));
    }
  }

  function custom1_default_form_submit ($form_id, $form_values) {
 // drupal_set_message( print_r($_POST));

 //  $message = 'You have submitted the ' . $form_id . ' form which contains the following data:<pre>' . print_r($form_state['values'],true) . '</pre>';

  //drupal_set_message(t($message));
  //drupal_set_message(t($form_values['values']['txt_name']));
 // print_r($form_values['values']);
    $GET_TXT_FIELD_VALUE = $form_values['values']['txt_name'];
    $INSERT_QUERY = "INSERT INTO sample (test_name) VALUES ('$GET_TXT_FIELD_VALUE')";
    if (db_result(db_query("SELECT COUNT(*) FROM {sample} WHERE test_name = '%s';", $GET_TXT_FIELD_VALUE))) {
        // User doesn't exist
        drupal_set_message(t('ALREADY EXIST.....'));
     }else{
        db_query($INSERT_QUERY)or die('Execution Failed');
        if(db_affected_rows()==1){
            drupal_set_message(t('VALUE INSERTED SUCCESSFULLY'));
        }else{
            drupal_set_message(t('VALUE INSERTED FAILED'));
        }
    }    
}

如果要通过URL传递参数,请使用:

如果您只想通过
drupal\u get\u form()
调用将参数传递给表单,只需将参数作为附加参数添加到:


我发现在Drupal 6.20中,您应该在回调函数定义中添加一个伪参数:

$block['content']=drupal_get_form('custom1_default_form',$arg1,$arg2)

//

函数custom1\u default\u form($dummy,$arg1,$arg2){//查看$dummy中存储的内容 // ... }尽可能避免使用arg()函数:

尽可能避免使用此函数,因为生成的代码比较困难 阅读。在菜单回调函数中,尝试使用命名参数。 请参阅menu.inc中的说明,了解如何构造 以争论为例。尝试使用此函数加载 元素,例如在节点页上加载节点, 改为使用菜单获取对象()

function custom1_default_form() {
  // Assuming the URL is http://example.com/admin/content/types:
  $arg1 = arg(1); // $arg1 = 'content'
  $arg2 = arg(2); // $arg2 = 'types'
  // ...
}
$block['content'] = drupal_get_form('custom1_default_form', $arg1, $arg2);

// ...

function custom1_default_form($form_state, $arg1, $arg2) {
  // ...
}