I have a website with lot's of users posting from different countries with their country flags displayed under the posted comments. Often I need to move comments from one page to another with Comment Mover module, which unfortunately changes comments IPs to that of admin's (#117462: Keep original posters IP address on move and #557340: Keep current authors IP address when others edit the node). So I need a tool to easily correct edited/moved comment's IP address whenever needed.
In order to do that I wanted to add a new field for IP address to comment_form, which would pull, display and record back every comment's IP address from/to 'comments.hostname' table. I am confused how to make comment_form to pull comment authors' IPs through hook_form_alter() and would appreciate any help.
This is my first trial to code a Drupal module, so bear with new Drupaller, please. I have only small start for now:
/**
* Implementation of hook_form_alter().
*/
function comment_editor_form_alter(&$form, $form_state, $form_id) {
switch($form_id) {
case 'comment_form':
//$output .= dsm($form);
break;
}
}
Following http://www.lullabot.com/articles/modifying-forms-drupal-5-and-6 I tried to output dsm($form) and it gives:
cid (Array, 2 elements)
pid (Array, 2 elements)
nid (Array, 2 elements)
uid (Array, 2 elements)
but, unfortunately, it does not provide value for hostname. So my question is how I make my custom module to pull IP of comment author form hostname table, display it on a separate and editable field and record it back to DB on submission of the comment form?
Comments
I have progressed little bit
I have progressed little bit further:
Unfortunately, this code neither update hostname (IP) nor displays comment author's hostname pulling it from database. I don't know what's wrong with my code, but it does not effect comments.hostname table at all.
Not sure about where you are
Not sure about where you are getting $hostname from, but perhaps you have assigned that variable and just didn't show it. If you did, then you don't have an 'insert' $op declared in the switch under hook_comment(). That could be the issue when creating the initial comment. Also, if your {comments} table does not have the new column for hostname, that could be the other issue. I would suggest putting your values in a separate table as I did in my post, rather than tacking them on in the {comments} table.
Best, and good luck.
Try the following
comment_editor.install
comment_editor.module is as below:
Nicholas, thank you for your
Nicholas, thank you for your feedback and suggestion to create a separate table. However Drupal's {comments} table has 'hostname' column by default and lot's of other modules, including http://drupal.org/project/countryicons which I am using to display's comment authors' flags, interact with it. So it would be more confusing to keep hostnames (IP addresses) of comment authors in two separate tables. That's why I wanted to pull and display every comment's IP form hostname {comments}'s 'hostname' column in an editable field and, if changed, to record to back to database.
anyone can help with
anyone can help with displaying and updating user IP from 'hostname' column of comments table without creating additional tables?
I think your issue is from
I think your issue is from the theme layer you are not outputting $comment->hostname. Perhaps you could do it via comment.tpl.php, or via a preprocess function like I mentioned in my last comment? I also know that the module author_pane can output hostname. Perhaps you should look into incorporating that module into your site?
Reading your first post
Reading your first post again, perhaps I misunderstood your issue slightly, I understand a bit better what you are trying to do, but can't really look at the idea now. I do have one idea on why your aforementioned attempts did not work. It could be that your module's weight is lower than the comment module, or whatever sets hostname in the comment table. Try altering the weight of your module to be higher.
Let me know if changing your
Let me know if changing your module's weight fixes it for you.
Best!