Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7498283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:25:16+00:00 2026-05-29T19:25:16+00:00

I have multilpe comment forms on the same page that popup in modal boxes

  • 0

I have multilpe comment forms on the same page that popup in modal boxes when trigger is clicked. The problem I’m having is if you submit the form once with nothing in the textarea the error is thrown that you need to enter a comment and all is well so far. Nowww…if you enter text and fill it out correctly and submit whatever text was entered will be submitted the number of failed attempts and I can’t figure out why.

the jquery:

$(".add-comment")
    .button()
    .click(function() {
    $(this).closest('.comments').find('.form-comment').submit(function() {
        $('.com-error').hide();
        $('.com-msg').hide();
        $.post('/do-comment.php', $(this).serialize(),
            function(data) {
                if(data.success)
                {
                    $('.com-msg').find('.info-msg').html(data.message);
                    $('.comments').find('.com-msg').slideDown().delay(2000).slideUp(500);
                }
                else
                {
                    $('.com-error').find('.error-msg').html(data.message);
                    $('.com-error').slideDown().delay(2000).slideUp(500);
                }
            }, 'json');
            return false;
    });
});

the php

if (!$user->isAuthorized()) {
    header('Location: index.php');
}else{

$i= 0;
    $cmt = array();
    if($_POST){
        $cmt['bid'] = filter_input(INPUT_POST, 'bid', FILTER_SANITIZE_STRING);
        $cmt['uid'] = $user->getId();
        $cmt['msg'] = filter_input(INPUT_POST, 'comment', FILTER_SANITIZE_STRING);
        if(trim($cmt['msg']) == '') {
            $data['success'] = false;
            $data['message'] .= 'You must enter a comment';
            $i++;
        }elseif(strlen($cmt['msg']) > 500) {
            $data['success'] = false;
            $data['message'] .= 'Your comment is to long.';
            $i++;
        }

        if($i <= 0){
            if(insertComment($cmt)){
                $data['success'] = true;
                $data['message'] = 'Added your comment!';
            }else{
                $data['success'] = false;
                $data['message'] .= 'Error adding your comment';
            }
        }
        echo  json_encode($data);
    }
    unset($_POST);
}

the insertComment function used above

function insertComment($comment = array()) {
    global $config;

    $sql = "INSERT INTO comments (bid, uid, message) VALUES ('".mysql_real_escape_string($comment['bid'])."', ".mysql_real_escape_string($comment['uid']).", '".mysql_real_escape_string($comment['msg'])."')";
    $result = mysql_query($sql, $config->db->con);
    if(!$result) {
    echo mysql_error();
        return false;
    }else{
        return true;
    }
}

the form

<div class="comments">
<div class="wrap">
';
if(!$user->isAuthorized()){
    $output .= '<center>You must be logged in to post comments</center>';
}else{
    $output .= '
    <form name="form-comment" class="form-comment" >
    <textarea name="comment" class="beat-comment"></textarea>
    <input type="hidden" name="bid" value="'.$id.'" />
    <br />
    <span class="fr"><button type="submit" class="add-comment">Add Comment</button></span>
    </form>';

    $output .= '
    <div class="com-msg">
        <div class="ui-widget">
            <div class="ui-state-highlight ui-corner-all" style="padding: 0 .7em;">
                <p>
                    <span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span>
                    <div class="info-msg">
                    <!-- MSG FROM AJAX REQUEST IF PRESENT-->
                    </div>
                </p>
            </div>
        </div>
    </div>
    <div class="com-error">
        <div class="ui-widget">
            <div class="ui-state-error ui-corner-all" style="padding: 0 .7em;">
                <p>
                    <span class="ui-icon ui-icon-alert" style="float: left; margin-right: .7em;"></span>
                    <div class="error-msg">
                    <!-- ERROR MSG FROM AJAX REQUEST IF PRESENT-->
                    </div>
                </p>
            </div>
        </div>
    </div>
    ';
}

Thanks NeoNexus combined both of ours for a solution

$(".add-comment")
    .button()
    .click(function() {
    var myForm = $(this).parent();
        $('.com-error').hide();
        $('.com-msg').hide();
        $.post('/do-comment.php', $(myForm).serialize(),
            function(data) {
                if(data.success)
                {
                    $(myForm).parent().find('.info-msg').html(data.message);
                    $(myForm).parent().find('.com-msg').slideDown().delay(2000).slideUp(500);
                }
                else
                {
                    $(myForm).parent().find('.error-msg').html(data.message);
                    $(myForm).parent().find('.com-error').slideDown().delay(2000).slideUp(500);
                }
            }, 'json');
            return false;
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T19:25:17+00:00Added an answer on May 29, 2026 at 7:25 pm

    Normally I would explain what your code is doing and how to fix it, but I’m very tired. Give this a whorl:

    jQuery:

    $('.add-comment').click(function(){
        var myForm = $(this).parent();
        $('.com-error').hide();
        $('.com-msg').hide();
        $.post('/do-comment.php', $(myForm).serialize(), function(data){
            if(data.success){
                $(myform).parent().find('.info-msg').html(data.message);
                $(myForm).parent().find('.com-msg').slideDown().delay(2000).slideUp(500);
            } else {
                $(myform).parent().find('.error-msg').html(data.message);
                $(myform).parent().find('.com-error').slideDown().delay(2000).slideUp(500);
            }
        }, 'json');
        return false;
    });
    

    Markup:

    <form class="form-comment" >
        <textarea name="comment" class="beat-comment"></textarea>
        <input type="hidden" name="bid" value="'.$id.'" />
        <br />
        <span class="fr">
            <input type="button" class="add-comment" value="Add Comment" />
        </span>
    </form>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page with multiple comment boxes. When someone clicks the submit button
So i have a page that is gonna have multiple modal popups. Each one
I have several dynamically created links and forms on one page named with IDs
I have some code that when a user clicks on a link Add Comment,
I'm crazy with multiple forms in the same page . every working fine when
I have a long string of comments that I'd like to split into multiple
I have multiple classes that all derive from a base class, now some of
I have multiple layers in an application and i find myself having to bubble
I have multiple threads (C# application running on IIS) running that all need to
I am developing a comments box that will save the comment through a JQuery

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.