如何在我的 drupal 注册网络服务中处理验证码?
How to deal with captcha in my drupal registration web service?
我通过 Drupal 7 上的服务模块创建了一个允许在网站上注册的服务。尝试它我收到一条消息说验证码尚未填写。我随请求发送了所有必需的数据,如姓名、密码或电子邮件,但由于明显的原因我无法发送验证码。
现在,更简单的解决方案是在我的网站上禁用验证码,但我真的不想这样做,因为必须为正常的 'human' 注册启用它。
那么,有一种方法可以针对来自 Web 服务的请求禁用验证码吗?或者其他任何正确的方法,因为我真的不知道如何正确使用网络服务,所以我想我在做一些概念性错误...
您可以使用 hook_form_alter() to remove the captcha elements from your form(s). For example, in a custom Drupal module 试试这个:
<?php
function my_module_form_alter(&$form, &$form_state, $form_id) {
//dpm($form);
// Disable captcha on Services user register form.
if ($form_id == 'user_register_form') {
if (arg(0) == 'my_services_endpoint_path') {
unset($form['captcha']);
}
}
}
?>
使用devel module's dpm()
function to inspect the form structure and find the name of the element. The example above work's for the captcha module. If you're using Mollom,我想你可以只使用unset($form['mollom']);
我通过 Drupal 7 上的服务模块创建了一个允许在网站上注册的服务。尝试它我收到一条消息说验证码尚未填写。我随请求发送了所有必需的数据,如姓名、密码或电子邮件,但由于明显的原因我无法发送验证码。 现在,更简单的解决方案是在我的网站上禁用验证码,但我真的不想这样做,因为必须为正常的 'human' 注册启用它。
那么,有一种方法可以针对来自 Web 服务的请求禁用验证码吗?或者其他任何正确的方法,因为我真的不知道如何正确使用网络服务,所以我想我在做一些概念性错误...
您可以使用 hook_form_alter() to remove the captcha elements from your form(s). For example, in a custom Drupal module 试试这个:
<?php
function my_module_form_alter(&$form, &$form_state, $form_id) {
//dpm($form);
// Disable captcha on Services user register form.
if ($form_id == 'user_register_form') {
if (arg(0) == 'my_services_endpoint_path') {
unset($form['captcha']);
}
}
}
?>
使用devel module's dpm()
function to inspect the form structure and find the name of the element. The example above work's for the captcha module. If you're using Mollom,我想你可以只使用unset($form['mollom']);