Php 需要一些关于Drupal$表单值的提示吗
我让dpm($form)工作。美好的这是查看数据的更好方法。我仍在试图弄清楚东西是从哪里来的,例如:位置经纬度。“经度”一词在20个不同的地方被引用。我认为这是一个可能的地方来隔离这个输入字段的文本框。dpm($form['#field#u info']['field#u store_lation']['location_settings']['form']['fields']) 有关于如何追踪单个输入元素的提示吗Php 需要一些关于Drupal$表单值的提示吗,php,arrays,drupal,drupal-fapi,Php,Arrays,Drupal,Drupal Fapi,我让dpm($form)工作。美好的这是查看数据的更好方法。我仍在试图弄清楚东西是从哪里来的,例如:位置经纬度。“经度”一词在20个不同的地方被引用。我认为这是一个可能的地方来隔离这个输入字段的文本框。dpm($form['#field#u info']['field#u store_lation']['location_settings']['form']['fields']) 有关于如何追踪单个输入元素的提示吗 **这不是答案,而是对我第一个问题的补充** 嗨,谷歌人- 我正在尝试使用ho
**这不是答案,而是对我第一个问题的补充** 嗨,谷歌人- 我正在尝试使用hook\u form\u alter修改现有表单 经过几个小时的摸索,我现在可以关闭表单的位置(经度/纬度)部分,如下所示: 未设置($form['field\u store\u latitude']) 但是,像这样关闭纬度是不起作用的:
取消设置($form['field\u store\u latitude']['0']['location\u settings']['form']['fields']['locpick']) 我找不到一种简单的方法将html源代码中的id和名称与Krumo生成的数组链接起来。 在这种情况下,id称为“edit-field-store-latitude-0-locpick-user-latitude” 我需要一个在Drupal表单中识别表单元素的配方或指南
我想我找到了一个解决办法
<?php
// allows you to alter locations fields, which are tricky to access.
// this will require a patch in location module described here:
// http://drupal.org/node/381458#comment-1287362
/**
* Implementation of custom _element_alert() hook.
*/
function form_overrides_location_element_alter(&$element){
// change some location descriptions
$element['locpick']['user_latitude']['#description'] = ' ' . t('Use decimal notation.');
$element['locpick']['user_longitude']['#description'] = ' ' . t('See <a href=!url target=_blank>our help page</a> for more information.', array('!url' => url('latlon_help')));
// or make them disappear entirely
unset($element['locpick']['user_longitude']);
unset($element['locpick']['user_latitude']);
}
/**
* Implementation of form_alter hook.
*/
function form_overrides_form_alter(&$form, $form_state, $form_id) {
switch ($form_id) {
case 'user_profile_form':
// change titles in user profile form
$form['account']['name']['#title'] = t('Login Name');
$form['account']['mail']['#title'] = t('Email');
break;
case 'retailer_node_form':
// let's check what is supposed to be here...
print '<pre>';
//print_r($form);
dsm($form);
print '</pre>';
// this works to remove the city
unset($form['field_myvar_latitude']['0']['#location_settings']['form']['fields']['city']);
// let's try #after_build property
$form['#after_build'][]='mymodule_after_build_mynode';
break;
}
}
function mymodule_after_build_mynode($form, $form_values) {
// This will not work for locations fields
return $form;
}`enter code here`
因此有一种秘密的方法来改变位置字段,您需要做的是使用\after\u builded
回调:
你能更准确地说,你想做什么?找出哪些模块向表单(节点表单)添加了表单字段?哎哟,Drupal真的应该提高生产率吗?位置模块是一个contrib模块,所以它实际上不是core的一部分。它的构建方式对于可维护性非常好,但是很难覆盖它。
/**
* Implements hook_form_alter().
*/
function mymodule_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'x_node_form') {
// alter the location field
if (isset($form['locations'])) {
$form['locations']['#after_build'][] = 'mymodule_alter_location_field';
}
}
}
/**
* Remove the delete checkbox from location element.
*/
function mymodule_alter_location_field($form_element, &$form_state) {
$location = $form_element[0]; // The location field which you can alter
return $form_element;
}