comment form challenge?
-
I need to make a new comment form to allow comments to be submitted from the main page, and inserted into the database. I don’t have a standard loop, which complicates things. As it stands, I have the various forms appearing after each post on the main page, but when I click submit, it just goes to a blank screen, trying to insert into wp-comments-post.php I assume. Here is my index.php, look at the form section I pulled from a typical comments.php file:
<?php get_header (); ?> <div id="box"> <?php $qry = "SELECT u.id, user_nicename, post_date, post_content, post_title, post_type, post_excerpt, comment_content, comment_author, comment_approved, comment_count, wp_posts.ID as post_id FROM wp_posts INNER JOIN wp_users AS u ON post_author = u.id LEFT JOIN wp_comments ON wp_posts.ID = comment_post_ID WHERE post_type='post' ORDER BY user_nicename ASC, post_date DESC"; $res = mysql_query($qry); if ($res) { while ($row = mysql_fetch_assoc($res)) { $author[$row['user_nicename']][]=$row; } foreach($author as $k => $v) { $orderbydate[$v[0]['post_date']][$k] = $v; } krsort($orderbydate); foreach ($orderbydate as $k => $v) { ksort($orderbydate[$k], SORT_STRING); } } $divIds = array('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'); $i = 0; foreach ($orderbydate as $date => $authors) { foreach ($authors as $author=> $posts) { echo '<div id="'.$divIds[$i++].'">'; if($author=="tony") { echo '<img src="http://www.hippievstony.com/wp-content/uploads/2009/12/tonyname.jpg">'; } elseif($author=="hippie") { echo '<img src="http://www.hippievstony.com/wp-content/uploads/2009/12/hippiename.jpg">'; } elseif($author=="eriku") { echo '<img src="http://www.hippievstony.com/wp-content/uploads/2009/12/erikuname.jpg">'; } elseif($author=="ben") { echo '<img src="http://www.hippievstony.com/wp-content/uploads/2009/12/benname.jpg">'; } elseif($author=="hingyi") { echo '<img src="http://www.hippievstony.com/wp-content/uploads/2009/12/hingyiname.jpg">'; } elseif($author=="chris") { echo '<img src="http://www.hippievstony.com/wp-content/uploads/chrisname.jpg">'; } elseif($author=="gabe") { echo '<img src="http://www.hippievstony.com/wp-content/uploads/gabename.jpg">'; } elseif($author=="bender") { echo '<img src="http://www.hippievstony.com/wp-content/uploads/bendername.jpg">'; } elseif($author=="jake") { echo '<img src="http://www.hippievstony.com/wp-content/uploads/jakename.jpg">'; } $lastPost = null; foreach($posts as $post) { if ($lastPost != $post['post_id']) { echo '<h2>' . $post['post_title'] . '</h2><small>' . $post['post_date'] . '</small>'; echo '<p>' . $post['post_content'] . '</p>'; echo '<p>' . $post['post_excerpt'] . '</p>'; ?> <form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform"> <?php if($user_ID) : ?> <p>Logged in as <a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php"><?php echo $user_identity; ?></a>. <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?action=logout" title="Log out of this account">Log out »</a></p> <?php else : ?> <p><input type="text" name="author" id="author" value="<?php echo $comment_author; ?>" size="10" tabindex="1" /> <label for="author"><small>Name <?php if($req) echo "(required)"; ?></small></label></p> <p><input type="text" name="email" id="email" value="<?php echo $comment_author_email; ?>" size="10" tabindex="2" /> <label for="email"><small>Mail (will not be published) <?php if($req) echo "(required)"; ?></small></label></p> <p><input type="text" name="url" id="url" value="<?php echo $comment_author_url; ?>" size="10" tabindex="3" /> <label for="url"><small>Website</small></label></p> <?php endif; ?> <p><textarea name="comment" id="comment" cols="50%" rows="1" tabindex="4"></textarea></p> <p><input name="submit" type="submit" id="submit" tabindex="5" value="Submit Comment" /> <input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" /></p> <?php do_action('comment_form', $post->ID); ?> </form> <?php echo '<p>' . $post['comment_content'] . '</p>'; echo '<p><small>-' . $post['comment_author'] . '</small></p>'; } $lastPost = $post['post_id']; } if ($post['comment_approved']=1) { if ($post['comment_author']){ echo '<p>' . $post['comment_content'] . '</p>'; echo '<p><small>-' . $post['comment_author'] . '</small></p>'; } else echo '<p>no comment author</p>'; } else echo '<p>comment awaiting approval</p>'; echo '<p>' . $post['comment_count'] . '</p>'; echo '</div>'; } } get_sidebar (); get_footer(); ?>
The topic ‘comment form challenge?’ is closed to new replies.