Drupal 6 Drupal 6:使用隐藏字段
我正在解决一个问题,即挂接字段、设置默认值并将其隐藏。问题是它接受默认值,但只向数据库提交值的第一个字符Drupal 6 Drupal 6:使用隐藏字段,drupal-6,Drupal 6,我正在解决一个问题,即挂接字段、设置默认值并将其隐藏。问题是它接受默认值,但只向数据库提交值的第一个字符 //Here is how I'm doing it $form['field_sr_account'] = array( '#type' => 'hidden', '#value' => '45'); 我想我构建数组的方式可能有问题,但我似乎无法理解。我发现了一篇帖子,其中有人找到了仅提交第一个字符的解决方案 //Here is the format of the solut
//Here is how I'm doing it
$form['field_sr_account'] = array( '#type' => 'hidden', '#value' => '45');
我想我构建数组的方式可能有问题,但我似乎无法理解。我发现了一篇帖子,其中有人找到了仅提交第一个字符的解决方案
//Here is the format of the solution to the post - but it's not hidden
$form['field_sr_account'][0]['#default_value']['value'] = '45';
如何将隐藏属性添加到此中?您是否尝试使用
\default\u value
而不是\value
另外,如果您试图将一些数据传递给submit,而这些数据不会以您应该使用的格式更改。您是否尝试过使用
\default\u value
而不是\value
另外,如果您试图将某些数据传递给submit,而这些数据不会以您应该使用的格式更改。答案实际上是分别设置值和隐藏属性,然后使用以下格式在submit处理程序中再次设置值 我不确定这是否都是必要的,我想我可能不需要在表单alter中指定它,但它是有效的,所以我将不讨论它
$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']));
答案实际上是分别设置值和隐藏属性,然后使用以下格式在提交处理程序中再次设置值 我不确定这是否都是必要的,我想我可能不需要在表单alter中指定它,但它是有效的,所以我将不讨论它
$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']));
一个有趣的解决方案 CCK隐藏字段
/**
* 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;
}
一个有趣的解决方案 CCK隐藏字段
/**
* 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;
}