Send value 0 or 1 of checkbox or button along with comment

0

I'm a beginner in development, I have an app that lets you comment text, image and audio.

However I wish there was a "send anonymously" field? with a checkbox or a button, and this comment did not display the user name and profile photo.

I'm using HTML in the comments display field when I do not want the avatar to appear:

<?php if ($do['comment']['anon'] == 1)  { ?>

And it works when I change the value to 1 manually in phpmyadmin. The problem is: how to send the value of the checkbox along with the text? Because to be successful, the moment the person clicks on comment, the column text, time, and anon should be filled. What would the checkbox code look like to send this value? (0 or 1?)

The comment box div is:

 <div class="post-commet-textarea dropdown">
        <div id="do_comment_combo" class="remove_combo_on_click do_comment_combo_<?php echo $do['story']['id']; ?>" onclick="Do_ShowCommentCombo(<?php echo $do['story']['id']; ?>);">
            <div style="display: flex;">
                <img class="avatar" src="<?php echo $do['user']['avatar'];?>"/>
                <textarea class="form-control comment-textarea textarea" placeholder="<?php echo $do['lang']['write_comment'];?>" type="text" onkeyup="Do_RegisterComment(this.value,<?php echo $do['story']['id']; ?>,<?php echo $do['story']['publisher']['user_id']; ?>, event, <?php echo (!empty($do['story']['publisher']['page_id'])) ? $do['story']['publisher']['page_id'] : '0'; ?>)" onkeydown="textAreaAdjust(this, 31,'comm'); " dir="auto"></textarea>
            </div>

My code to send the comment works perfectly, and is as follows:

The "comments" table has the columns:

1-id (save id of comment),

2-user_id (save id of the user who commented),

3-page_id (save the id of the page that the user commented on),

4-post_id (save the post id the user commented on),

5-text (save comment),

6-c_file (photos and audios),

7-time (comment date) and

8-ANON (WHERE I WANT TO STORE CHECKBOX VALUES 0 OR 1)

(Do_ is the prefix of my tables)

if ($s == 'register_comment') {
    if (!empty($_POST['post_id']) && isset($_POST['text'])) {
        $html    = '';
        $page_id = '';
        if (!empty($_POST['page_id'])) {
            $page_id = $_POST['page_id'];
        }
        $comment_image = '';
        if (!empty($_POST['comment_image'])) {
            if (isset($_SESSION['file']) && $_SESSION['file'] == $_POST['comment_image']) {
                $comment_image = $_POST['comment_image'];
                unset($_SESSION['file']);
            }
        }
        if (empty($comment_image) && empty($_POST['text']) && empty($_POST['audio-filename'])) {
            header("Content-type: application/json");
            echo json_encode($data);
            exit();
        }
        $text_comment = '';
        if (!empty($_POST['text']) && !ctype_space($_POST['text'])) {
            $text_comment = $_POST['text'];
        }

        $C_Data = array(
            'user_id' => ($do['user']['user_id']),
            'page_id' => ($page_id),
            'post_id' => ($_POST['post_id']),
            'text' => ($_POST['text']),
            'c_file' => ($comment_image),
            'time' => time()
        );
        if (!empty($_POST['audio-filename']) && isset($_FILES["audio-blob"]["tmp_name"])) {
            $fileInfo         = array(
                'file' => $_FILES["audio-blob"]["tmp_name"],
                'name' => $_FILES['audio-blob']['name'],
                'size' => $_FILES["audio-blob"]["size"],
                'type' => $_FILES["audio-blob"]["type"],
                'types' => 'mp3,wav'
            );

            $C_Data['record'] = $media['filename'];
        }
        $R_Comment     = Do_RegisterPostComment($C_Data);
        $do['comment'] = Do_GetPostComment($R_Comment);
        $do['story']   = Do_PostData($_POST['post_id']);
        if (!empty($do['comment'])) {
            $html = Do_LoadPage('comment/content');
            $data = array(
                'status' => 200,
                'html' => $html,
                'comments_num' => Do_CountPostComment($_POST['post_id'])
            );

        }
    }
    header("Content-type: application/json");
    echo json_encode($data);
    exit();
}
    
asked by anonymous 10.10.2018 / 05:19

0 answers