1 (edited by 2009-02-18 17:06:06)

Topic: [TUTORIAL][HACK] Saving additional data with comments.

Name: Saving additional data with comments.
Author: Rokker93
CuteNews Compatibility: 1.3.6 - * (no incompatibility reported yet)
Description: This topic will explain how to add new fields to comments, so your users can add more information, It is alittle long and rather complex for what It Is, but It will work on newer and older versions of CN.

Instructions:
Now before we start, do understand that this is a TUTORIAL. So don't just go copy and past everything. Please do try and understand what you're doing.

1) shows.inc.php find

        $name = trim($name);

Add under it

        $NAME = trim($NAME);

Replacing NAME, with a word related to the information you're storing, no spaces or special characters please.
$NAME will be used later on awell. So the samse change should be made to those aswell.

2) Find

             <input type=\"hidden\" name=\"ucat\" value=\"$ucat\" />

Underneath add:

             <input type=\"hidden\" name=\"NAME\" value=\"$NAME\" />

Replacing NAME, with a word chosen In step 1.

3) [This stops the field being blank. If you don't want this, then skip to step 4]
Find

    if($name == " " or $name == ""){
            echo("<div style=\"text-align: center;\">You must enter name.
[url=]go back[/url]</div>");
                $CN_HALT = TRUE;
                break 1;
        }

and add underneath

    if($NAME == " " or $NAME == ""){
            echo("<div style=\"text-align: center;\">You must fill In all the fields!.
[url=]go back[/url]</div>");
                $CN_HALT = TRUE;
                break 1;
        }

Again, replacing NAME with the word used in step 1! You may also change the message.

4) Next find

    if($mail == " " or $mail == ""){ $mail = "none"; }

Underneath add:

    if($NAME == " " or $NAME == ""){ $NAME = "none"; }

5) Find:

        fwrite($new_comments, "$old_comments_arr[0]|>|$old_comments_arr[1]$time|$name|$mail|$ip|$comments||\n");


And add |$NAME after $comments, so It would look like

        fwrite($new_comments, "$old_comments_arr[0]|>|$old_comments_arr[1]$time|$name|$mail|$ip|$comments|$NAME||\n");

Again, replacing NAME with the word used in step 1!
And make sure that at the end of the string there are 2 | as you see demonstrated in the 2 above codes and the code below. Else CN will have trouble splitting the information in seperate comments and will consider it as 1 comment.

If you're adding more then one field to comments, then just keep adding the variable name, as you did with $NAME, eg.

fwrite($new_comments, "$old_comments_arr[0]|>|$old_comments_arr[1]$time|$name|$mail|$ip|$comments|$new_var1|$new_var2|$etc||\n");

6) We have validated and saved the information, now we just need to add a input field for the people !
In your comments template (so please do use the template editor in your CN panel, and don't edit the tpl files), add

<input type="text" name="NAME" value="Enter Text.." />

Replacing NAME again.
Ofcourse you're not obligate to use this. You can just aswell make a dropdownbox, or use checkboxes. As long as you won't forget to add the 'name' attribute.

7) Now lets show the people what we have stored!
In shows.inc.php still, find

$output = str_replace("{comment}", "<a name=\"".$comment_arr[0]."\"></a>$comment_arr[4]",$output);


And add underneath:

if($comment_arr[5] != "none"){ $output = str_replace("{NAME}",  $comment_arr[5], $output); }
else { $output = str_replace("{NAME}", '', $output); }


If you are adding two fields, have one line with $comment_arr[5] and one with $comment_arr[6] etc.
So each time you add a new data to your comments, a new slot for that data will be added to comments.txt
The number will tell CN for which slot you want to get the data and replace the tag with that data.
Replacing NAME again.

// HOW TO EDIT COMMENTS.

Open inc/editcomments.mdu
Find:

    <tr>
    <td height=20 valign=middle valign=\"top\" width=\"102\" bgcolor=\"#F9F8F7\">
    IP
    <td height=20 valign=middle width=\"1002\" bgcolor=\"#F9F8F7\">
    [url=]$single_arr[3][/url]   
    [url=][ban this ip][/url]
    </tr>


Add underneath:

    <tr>
    <td height=20 valign=middle valign=\"top\" width=\"102\">
    NAME
    <td height=20 valign=middle width=\"1002\" bgcolor=\"#F9F8F7\">
    <input type="text" name="NAME" value=$single_arr[5]" /></a>
    </tr>


Replacing NAME again and use the correct slot number.

Now find:

fwrite($new_com,"$comment_arr[0]|$poster|$mail|$comment_arr[3]|$comment||");

And same as before, add |$NAME after $comment

fwrite($new_com,"$comment_arr[0]|$poster|$mail|$comment_arr[3]|$comment|$NAME||");

This is basics on how to add fields to comments, you can do this as many times as you want, just follow the same idea.

Posts: 3

Pages 1

You must login or register to post a reply

CutePHP Forums → Hacks & Tricks / FAQ → [TUTORIAL][HACK] Saving additional data with comments.