自动完成而不使用回调
我想使用链接到外部源的自动完成字段来获取自动完成数据。 Drupal 似乎拒绝所有在 Drupal 内无法访问的 autocomplete_path。有什么想法可以避免这个问题吗?表单字段如下所示:
$form['business_city'] = array(
'#type' => 'textfield',
'#size' => 30,
'#title' => t('city'),
'#autocomplete_path' => '_/city?=',
'#default_value' => $userProfile->field_address_business_city[0]['value'],
);
出于性能原因,在 Drupal 中无法访问 _/city。该脚本将 Drupal 引导至会话级别以检查有效登录。
更新:
如果我通过将所需的标记手动附加到字段来创建自动完成字段,它可以工作,但维护起来很困难:
'#attributes' => array('class' => 'form-autocomplete'),
'#suffix' => '<input type="hidden" disabled="disabled" value="/_/city?n=" id="edit-private-city-autocomplete" class="autocomplete">',
I want to use autocomplete-fields that link to an external source for their autocomplete-data. Drupal seems to refuse all autocomplete_paths that are not reachable within Drupal. Any ideas how to circumvent that problem? The form field looks like that:
$form['business_city'] = array(
'#type' => 'textfield',
'#size' => 30,
'#title' => t('city'),
'#autocomplete_path' => '_/city?=',
'#default_value' => $userProfile->field_address_business_city[0]['value'],
);
_/city is not reachable within Drupal for performance reasons. The script bootstraps Drupal up to session-level to check for a valid login.
UPDATE:
If I create an autcomplete-field by attaching the needed markup manually to the field it works but it is awkward to maintain:
'#attributes' => array('class' => 'form-autocomplete'),
'#suffix' => '<input type="hidden" disabled="disabled" value="/_/city?n=" id="edit-private-city-autocomplete" class="autocomplete">',
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以确保查询“/_/city?n=”的路径是有效的 menu_hook 项,而不是进行黑客攻击。这样它将根据 theme_textfield() 内的 drupal_valid_path() 进行验证。然后,您可以从菜单挂钩函数回调中将请求转发到外部数据源。
Instead of hacking, you could make sure that the path you are querying "/_/city?n=" is a valid menu_hook item. That way it will validate against the drupal_valid_path() inside theme_textfield(). From within the menu hook function callback you could then forward the request to your external data source.
Drupal 6 在 theme_textfield() 中验证,如果自动完成路径是有效的(内部)路径。
因此,除非您重写该主题函数,否则无法解决此问题。
Drupal 6 validates in theme_textfield() if the autocomplete path is a valid (internal) path.
So, you can't work around this unless you override that theme function.