Basically I am working on creating a photo-gallery content type for my site. Each gallery is a node, with multiple CCK imagefields attached to it. Depending on what the $_GET value is it displays the specific image. IE node/22?pic=0 is the first picture, node/22?pic=1 the second etc.
The problem I have is regarding commenting. I want people to be able to comment on each picture individually, which means I have to pass some bit of data with each comment referring to what picture is currently being viewed.
So I added a hidden field using hook_form_alter to my comment form. Here's the code.
<?php
function owen_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'comment_form') {
$form['pic'] = array(
'#type' => 'hidden',
'#value' => $_GET['pic'],
'#default_value' => $_GET['pic']
);
}
}
?>The field correctly appears in the form. The problem I have is processing the data from that form. I have created a simple module, which created a table in the database to handle the data from this new field. Except, when I process the data from $comment in hook_comment the field pic is blank.
Because the data is entered into the field using $_GET['pic'] when I use hook_comment, the $comments var shows blank, i'm assuming because at the page where hook_comments() exists the $_GET array no longer exists. Here is my implementation of hook_comment. In testing, if I modify my field data in hook_form_alter to set a specific value for #value for $form['pic'] then it works perfectly. When I set the value with a $_GET var it always goes blank. Yet, I do not see an alternative to reading the data from a $_GET var. Here is my implementation of hook_comment.
<?php
function owen_comment(&$comment, $op) {
switch($op) {
case 'insert':
db_query("INSERT INTO {owen} (cid, nid, pic) VALUES(%d, %d, %d)", $comment['cid'], 2, $comment['pic']);
break;
}
}
?>I have been playing around with this for a very long while, I found that I can create an alternate submit function, which basically pulls the data out of the #post array in the $form var, but I feel like that is a very hackery solution. If worst comes to worst I can do it, but I really feel there must be some way to do this with hook_comment. Any clues?
Sorry for the confusion but I am fairly new to Drupal, my eyes are crossing from staring at comment.module for the last 3 hours.