1

I have enabled provision for Anonymous commenting. But it provides the only option of

  1. Your Name
  2. Email Address
  3. Homepage

What I would like is, above this, there should be a provision of Login. Hence this way user can see that, So he/she will have two options, either he/she can login OR he/she can comment anonymously.

What happen with current system is, Anonymous user keep on commenting as anonymous only, If there is a option of Login, then he may think about that.

So, I would like to make the system in commenting like,

Add Comment

**Login/create account**

OR

**Comment Anonymously**

Your-name*  |  Email*  |  Homepage 

Comment field

Update:

I just need a Link, like what appears above the comments title on every drupal site, as shown in following image, Log in or register to post comment

Image

Image

  • Yeah sure, just have a look at drupal's form API reference: api.drupal.org/api/drupal/… you can use the code in the form alter hook of my previous answer – Neograph734 Jun 16 '16 at 15:15
  • Could you please provide the answer if you can, I tried but I am not understanding this one, how to extract and combine all things. Very thanks for help. – CodeNext Jun 17 '16 at 16:50
  • I was on my phone yesterday, so could not write a detailed answer. Can you update the question with what you have tried? Also do you want the login/create account to be a link, or a form? – Neograph734 Jun 17 '16 at 17:21
  • Hi, I do not have any code to show, I was trying to follow your previous answer, where the function was clear. But in this case, on the drupal API page I did not find the specific function or I did not understand how to use. Why I am asking for help in coding is, I am not from this field and no knowledge of codes. Even I am trying to do all stuff in my site with modules only, so no coding need to do. But some part need to customize, so codes needed. Sorry for my lake of knowledge, You can understand..:) Just your answer appeared now, following that. – CodeNext Jun 17 '16 at 17:35
  • No problem, I was on my phone yesterday so I could not write a proper answer. Just keep in mind that we are not a code writing service. My previous answer was 3 lines, this is already a bit longer. For more difficult questions the answers tend to become more like guides rather then full code snippets. I guided you to Form API documentation to get some understanding on Drupal's form system so maybe you could figure it out on your own. Just let me know if this solution works for you :) – Neograph734 Jun 17 '16 at 17:39
1

Since you want to edit something in the contact form, you can use the same hook_form_FORM_ID_alter of my previous answer to alter the comment_form.

As you can see in the comment form all author details are in an array $form['author']. So you need to add an item to this array and move it to the top.

function MODULENAME_form_comment_form_alter(&$form, &$form_state, $form_id) {
  // Any code you already have here

  // Check if the user was not yet logged in. (It would be useless to show this otherwise.)
  if (!user_is_logged_in()) {

    $form['author']['login_url'] = array(
      '#type' => 'markup',
      '#markup' => t('<a href="@login">Login</a> or <a href="@create">create account</a>', array('@login' => url('user/login'), '@create' => url('user/register'))),
      '#weight' => -10, // Play with this value to control the height.
    );
  }
}
  • 1
    Hi, this code is working fine. No issue. Very very thanks for you answer/help. And have taken notes of your last comment. Very thanks. – CodeNext Jun 17 '16 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.