English 中文(简体)
第6博士:与隐蔽领域合作
原标题:Drupal 6: Working with Hidden Fields
  • 时间:2010-01-10 17:35:48
  •  标签:
  • drupal-6

我正在处理一米问题,它带有一个领域,设定了违约价值,并隐藏了它。 问题是,它正在承担违约价值,而只是向数据库提交价值的第一特性。

//Here is how I m doing it
$form[ field_sr_account ] = array(  #type  =>  hidden ,  #value  =>  45 );

我认为,我组织我的阵列的方式是错误的,但我看不到。 I found a post, 某人只找到了第一种特性的解决办法

//Here is the format of the solution to the post - but it s not hidden
$form[ field_sr_account ][0][ #default_value ][ value ] =  45 ;

我怎么能够加上这种隐蔽的特性?

最佳回答

答案实际上是要分别确定价值和隐藏的属性,然后使用以下格式在提交书记人中再次确定价值。

我不敢肯定,如果我认为有必要的话,我就认为我可能没有必要以改变的方式分配,但我会干 works,这样我就能够单独离开。

$form[ #field_sr_account ] = $club;
    $form[ field_sr_account ] = array(  #type  =>  hidden , #value  => $club);
   }
}

/*in submit handler, restore the value in the proper format*/
$form_state[ values ][ field_sr_account ] = array( 0  => array( value  => $form[ #field_sr_account ]));
问题回答

http://drupal.org/node/257431#comment-2057358"rel=“nofollow”

< Hidden Fields

/**
* Implementation of hook_form_alter().
*/
function YourModuleName_form_alter(&$form, $form_state, $form_id) {
  if (isset($form[ type ]) && isset($form[ #node ])) {
    ### Make a CCK field becoming a hidden type field.
    // ### Use this check to match node edit form for a particular content type.
    if ($form_id ===  YourContentTypeName_node_form ) {
      $form[ #after_build ] = array( _test_set_cck_field_to_hidden );
    }
  }
}

function _test_set_cck_field_to_hidden($form, &$form_state) {
  $form[ field_NameToBeHidden ][0][ value ][ #type ] =  hidden ;
  $form[ field_NameToBeHidden ][0][ #value ][ value ] =  testValue ;

  return $form;
}




相关问题
drupal form textfield #default_value not working

I am working on a custom module with multi-page form on drupal 6. I found that #default_value is not working when my #type => textfield . However, when #type => textarea , it displays correctly ...

Syntax Highlighting in Drupal

Which is the best module for Syntax Highligting in Drupal. I am using GeSHi for syntax highlighting my code. It was working fine then I installed a second module FCKeditor. Now GeSHi filter is not ...

Conditional link to node within views?

I have two content types, book and chapter. Each chapter node contains a node reference of the book to which it belongs. I have created a view which displays the title of each chapter for a given ...

Foreach in SQL?

I m not quite sure how to do this in SQL. Here it is in pseudocode: Take the list of nodes with content type X. For each node, take the value of field Y. Insert into term_nodes VALUES ((tid that ...

Drupal section accessible by role

I need to limit access of content on Drupal site based on the Drupal User s Role. http://site.com/managers/intro http://site.com/managers/reviews http://site.com/managers/up-for-raises The ...

Ungroup user menu in Drupal

I am using Drupal 6.x with Zen theme. Currently, the following 3 user functions are grouped under a menu, when accessing urls like http://domain.com/user Create new account / Log in / Request ...

热门标签