开发者

Drupal 7 anonymous comments, disable homepage field

In Drupal 7 comments, how can I hide/disable homepage field for ano开发者_如何转开发nymous commenters?


Whilst there are lots of answers here none of them provide all of the code in one easy to copy and paste block:

/**
* Implements hook_form_FORM_ID_alter().
*
* Remove homepage field from comments form.
*/
function THEMENAME_form_comment_form_alter(&$form, &$form_state) {
    $form['author']['homepage']['#access'] = FALSE;
}

Put this code in your themes template.php replacing THEMENAME with the name of your theme.


Open the file themes/<your_theme>/templates/comment-wrapper.tpl.php in your drupal installation folder, and add this line before the HTML code:

<?php $content['comment_form']['author']['homepage'] = null; ?>

or at least before

<?php print render($content['comment_form']); ?>

With that you're deactivating the homepage field in the form that is displayed to the user.

You can also do what @Robert says and choose "Anonymous posters may not leave their contact info", but you'd be allowing comments without email information as well. If you just want to hide the homepage field from the form and keep the email (for example, to use Gravatar), this bit of hacking should do the trick. If your website has more than one theme, make sure you do it in every theme that displays the comments form.


In a suitable form_alter() hook, do this:

$form['author']['homepage']['#access'] = FALSE;

This is better than using unset() or setting $form['author']['homepage'] to null as described in other answers, because the comment_form_validate() function throws ugly errors.

All credit to Art Williams


Administration » Structure » Content types » (Your content type) » Comment Settings » Anonymous commenting » Anonymous posters may not / may /must leave their contact info.


Here's the three-line custom module solution. I usually keep a custom_site_tweaks module for this type of thing per site.

function CUSTOM_form_comment_node_blog_post_form_alter(&$form, &$form_state, $form_id) {
  unset($form['author']['homepage']);
}

BTW: This is a great way to de-incentivize spam posts.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜