Changing the default generic comment box

Ive been trying to change the default elgg comment box to look more like "river_comments" comment box.

ive got pretty far but i recieve this error afer posting a comment "Sorry, you need to actually put something in your comment before we can save it."

this is my code on views/comment/forms/edit.php

<?php
/**
 * Elgg comments add form
 *
 * @package Elgg
 *
 * @uses $vars['entity']
 */

if (isset($vars['entity']) && isloggedin()) {
    $form_body = "<div class=\"comment_box\">
        
        <div class=\"comment_feed comment_add_box\">
        
<form    action=\"http://www.fakepals.com/action/comment\" method=\"post\" >
    " . elgg_view('input/securitytoken')  . "
    <input type=\"hidden\"  name=\"guid\"  value=\"" . $entity_guid . "\" />

                    <div class=\"comment_icon\"> " .
                    
                    elgg_view("profile/icon",array(
                                'entity' => $user,
                                'size' => 'tiny',
                                'override' => true)
                            ) ."
                            
                            </div>
                            
                            <textarea onclick=\"rcPrepareItems(); readyToWrite(this)\" name=\"river_comment_text\"> "

.  elgg_echo('river_comments:writeacomment1') . "</textarea>
                        
                            <input type=\"submit\" name=\"comment\" value=\"Comment\" />
                    
                        </form>
                            
                </div>
    </div>";

    echo elgg_view('input/form', array('body' => $form_body, 'action' => "{$vars['url']}action/comments/add"));

}

 

 

can anyone tell me whats wrong with my code?  any help would be great!  bear with me im a nobe coder.

  • ok best thing to do is at the very top of the action file add the following code:

    <?php

    $the_comment = get_input('river_comment_text');

    echo $the_comment;

    exit();

    ?>

    The name of the text area in both your examples is not "generic_comment" but "river_comment_text" so your action file might be looking for the wrong thing.

    Type a comment and save it, you'll get a blank white screen hopefully with your comment showing at the top. If you see the comment on the blank page then it's coming through and you need to change your action file (and what it's looking for) to the above. 

    Hint when you're ready to fully test it, remove the echo & exit code.

  • one last thing...your submit input really doesn't need the name "comment". Give it any name you like, it doesn't matter. Leaving it as comment gets confusing when you are actually working with comments. 

  • I get a white screen with my comment!!!!

    so that leaves the action to blame. 

    this is my action file

    <?php
    /**
     * Elgg add comment action
     *
     * @package Elgg
     * @author Curverider <curverider.co.uk>
     * @link http://elgg.org/
     */

    // Make sure we're logged in; forward to the front page if not
    gatekeeper();

    // Get input
    $entity_guid = (int) get_input('entity_guid');
    $comment_text = get_input('generic_comment');

    // make sure comment is not empty
    if (empty($comment_text)) {
        register_error(elgg_echo("generic_comment:blank"));
        forward($_SERVER['HTTP_REFERER']);
    }

    // Let's see if we can get an entity with the specified GUID
    $entity = get_entity($entity_guid);
    if (!$entity) {
        register_error(elgg_echo("generic_comment:notfound"));
        forward($_SERVER['HTTP_REFERER']);
    }

    $user = get_loggedin_user();

    $annotation = create_annotation($entity->guid,
                                    'generic_comment',
                                    $comment_text,
                                    "",
                                    $user->guid,
                                    $entity->access_id = 2);

    // tell user annotation posted
    if (!$annotation) {
        register_error(elgg_echo("generic_comment:failure"));
        forward($_SERVER['HTTP_REFERER']);
    }

    // notify if poster wasn't owner
    //load description
        if (strlen($comment_text) > 90) {
            $notice = substr($comment_text, 0, strpos($comment_text, ' ', 90)) . "... (cont'd)";
        } else {
            $notice = $comment_text;
        }
    if ($entity->owner_guid != $user->guid) {

        notify_user($entity->owner_guid,
                    $user->guid,
                    elgg_echo('generic_comment:email:subject'),
                    sprintf(
                        elgg_echo('generic_comment:email:body'),
                        $user->name,
                        $entity->title,
                        $comment_text,
                        $entity->getURL(),
                        $user->name,
                        $user->getURL()
                    ),
    $live = " has commented on your item <a href=\"". $entity->getURL() . "\"> CLICK HERE TO SEE IT! </a>"
                        );

    }

    //Notify everybody!
    //extract annotations and ping each!
        //$commenters = get_annotations($entity->guid, "", "", 'generic_comment', , get_loggedin_userid(), 1);
        $commenters = get_annotations($entity->guid, "", "", 'generic_comment');
        $pinged_users = array('');
        foreach ($commenters as $item)
        {
        $cowner = $item->getOwnerEntity();
        $commenter_guid = $cowner->guid;
        //dont notify poster and owner again!
        if ($user->guid != $commenter_guid && $entity->owner_guid != $commenter_guid){
        if (!in_array($commenter_guid, $pinged_users )) {
                    notify_user($commenter_guid,
                    $user->guid,
                    elgg_echo('generic_comment:email:subject2'),
                    sprintf(
                        elgg_echo('generic_comment:email:body2'),
                        $user->name,
                        $entity->title,
                        $comment_text,
                        $entity->getURL(),
                        $user->name,
                        $user->getURL()
                    ),
    $live = " has commented under your comment <a href=\"". $entity->getURL() . "\"> CLICK HERE TO SEE IT! </a>"
                        );

                }
                $pinged_users[] = $commenter_guid;
        }
        }
    system_message(elgg_echo("generic_comment:posted"));
    //add to river
    //add_to_river('annotation/annotate','comment',$user->guid,$entity->guid, "", 0, $annotation);

    // Forward to the entity page
    forward($entity->getURL());

     

    I changed the comments name from

    name=\"river_comment_text\">

    to

    name=\"generic_comment\">

    the comment file looks like this

    <?php
    /**
     * Elgg comments add form
     *
     * @package Elgg
     *
     * @uses $vars['entity']
     */

    if (isset($vars['entity']) && isloggedin()) {
        $form_body = "<div class=\"comment_box\">

            <div class=\"comment_feed comment_add_box\">

    <form    action=\"http://www.fakepals.com/action/comment\" method=\"post\" >
        " . elgg_view('input/securitytoken')  . "
        <input type=\"hidden\"  name=\"guid\"  value=\"" . $entity_guid . "\" />

                        <div class=\"comment_icon\"> " .

                        elgg_view("profile/icon",array(
                                    'entity' => $user,
                                    'size' => 'tiny',
                                    'override' => true)
                                ) ."

                                </div>

                                <textarea onclick=\"rcPrepareItems(); readyToWrite(this)\" name=\"generic_comment\"> "

    .  elgg_echo('river_comments:writeacomment1') . "</textarea>

                                <input type=\"submit\" name=\"comment\" value=\"Comment\" />

                            </form>

                    </div>
        </div>";

        echo elgg_view('input/form', array('body' => $form_body, 'action' => "{$vars['url']}action/comments/add"));

    }

    Thanks for all your help Trajan.

  • Best thing to do at this point is to enable display_errors in PHP.

  • How would one display_errors?  phpini?

  • I think im getting closer.

    this is my new comment.

    <?php
    /**
     * Elgg comments add form
     *
     * @package Elgg
     *
     * @uses $vars['entity']
     */

    if (isset($vars['entity']) && isloggedin()) {
        $form_body = "<div class=\"comment_box\">

            <div class=\"comment_feed comment_add_box\">

    <form   
        <input type=\"hidden\"  name=\"guid\"  value=\"" . $entity_guid . "\" />

                        <div class=\"comment_icon\"> " .

                        elgg_view("profile/icon",array(
                                    'entity' => $user,
                                    'size' => 'tiny',
                                    'override' => true)
                                ) ."

                                </div>

                                <textarea onclick=\"rcPrepareItems(); readyToWrite(this)\" name=\"generic_comment\"> "

    .  elgg_echo('river_comments:writeacomment1') . "</textarea>

                                <input type=\"submit\" name=\"comment\" value=\"Comment\" />

                            </form>

                    </div>
        </div>";

        echo elgg_view('input/form', array('body' => $form_body, 'action' => "{$vars['url']}action/comments/add"));

    }

  • to display errors, go to your .htaccess file and where it says something about PHP errors and says "0", change that to a 1. Then errors will display. These are generally very useful for telling you where you have an error in your coding, but you need to get used to them to find the actual error.

    Anyway, keep plugging away, you'll get it working the way you want soon enough!