我希望Drupal的评论能像其他博客的评论一样发挥作用。谁在写他们的主页URL可以写“www.example.com”或“http://www.example.com”,他们都工作。现在,如果URL不包含“http://。”
,Drupal会抛出错误答案 0 :(得分:1)
您可以覆盖comment_validate
中的/modules/comment/comment.module
挂钩并修改验证码,以便将http://
位插入到URL中(如果它尚未存在)。更改后的代码看起来像:
if ($edit['homepage']) {
if (!strpos($edit['homepage'], "http://")) {
$edit['homepage'] = "http://" . $edit['homepage'];
}
if (!valid_url($edit['homepage'], TRUE)) {
form_set_error('homepage', t('The URL of your homepage is not valid. Remember that it must be fully qualified, i.e. of the form <code>http://example.com/directory</code>.'));
}
}
您还需要覆盖comment_form_validate
挂钩:
function comment_form_validate($form, &$form_state) {
global $user;
if ($user->uid === 0) {
foreach (array('name', 'homepage', 'mail') as $field) {
// Set cookie for 365 days.
if (isset($form_state['values'][$field])) {
setcookie('comment_info_'. $field, $form_state['values'][$field], time() + 31536000, '/');
}
}
}
$form_state['values'] = comment_validate($form_state['values']);
}
答案 1 :(得分:1)
strpos行应
strpos($edit['homepage'], "http://") === FALSE
https://drupal.stackexchange.com/questions/1037/allow-comment-homepage-urls-without-http