小编Ard*_*ved的帖子

Drupal FAPI错误; 无法创建对字符串偏移或来自重载对象的引用

我正在尝试在我的用户注册页面上的几个文本字段中添加一些自定义自动完成功能,与本教程一致; http://drupal.org/node/854216.

我已经能够成功实现这一目标,但现在每当我提交注册表单时,我都会得到一个空白页面,并且此错误会显示在日志中;

PHP致命错误:无法在第6448行的/var/www/html/drupal/includes/common.inc中创建对字符串偏移或重载对象的引用,引用:http:// [...]/drupal /?q =用户/寄存器

我现在找不到这个主题,但是当我最初在谷歌上搜索这个问题时,我在某处读到这个问题通常是从属性键中添加或遗漏了'#'符号.因为没有#符号,它会将该属性的值视为子元素,从而将数组视为一个元素.或者沿着这些方向的东西,但经过仔细检查之后,似乎我正在使用的所有属性都应该像我已经放置它们一样.

这是代码,有谁知道我做错了什么?

function gtx_alterations_menu() {
  $items = array();
  $items['city/autocomplete'] = array(
    'page callback' => 'city_autocomplete',
    'access callback' => TRUE,
    'type' => MENU_CALLBACK
  );
  return $items;
}

function gtx_alterations_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'user_register_form') {
    $form['field_city_of_residence']['#type'] = 'textfield';
    $form['field_city_of_residence']['#title'] = t('City of Residence');
    $form['field_city_of_residence']['#autocomplete_path'] = 'city/autocomplete';
    $form['field_headquarters_location']['#type'] = 'textfield';
    $form['field_headquarters_location']['#title'] = t('Headquarters Location');
    $form['field_headquarters_location']['#autocomplete_path'] = 'city/autocomplete';
  }
}

function city_autocomplete($string = '') {
  $cities = array();
  $locations = array();
  $results = …
Run Code Online (Sandbox Code Playgroud)

php drupal drupal-7

5
推荐指数
1
解决办法
6000
查看次数

标签 统计

drupal ×1

drupal-7 ×1

php ×1