1
<?php for($i = 0; $i < $pin_num_rows; $i++){ ?>
<form action="/group/<?php echo $group_id ?>?Comment=<?php echo $pin_id[$i] ?>" method="post" id="group-comment-form">
<textarea name="group-comment" id="group-comment" placeholder="Add a comment..."  spellcheck="false"></textarea>
</form>
<?php } ?>

This is the some part of my code. As you can see, I am passing the value of pin_id in my form action. The problem is, whenever I post comment, the form submits the value with /group/?Comment=1 but it supposed to submit with 1, when I comment to the first post. So, when I comment to the second post, it supposed pass 2 but it doesn't. It always passes /group/?Comment=1

I did echo this right after my textarea and I see that for every comment form, the number increments as it should be but when I submit, it submits with value 1. I am going crazy.

<?php echo "/group/<?php echo $group_id ?>?Comment=$pin_id[$i]" ?>

I have also this part in my code in the same loop above and it has the same logic but it works. I don't understand why the form part doesn't work.

<a href="/group/<?php echo $group_id ?>?Edit=<?php echo $pin_id[$i] ?>" title="Edit" id="group-edit-button">Edit</a>
<a href="/group/<?php echo $group_id ?>?Delete=<?php echo $pin_id[$i] ?>" title="Delete" id="group-delete-button">Delete</a>

EDIT

I wrote this simple program which demonstrates the same logic that I used for the site and this simple program works but website. I guess the problem is not about the names of form or textarea.

<?php
$inputValue = NULL;
$id = [1,2,3];

if(isset($_POST['inputName'])){
$inputValue = $_POST['inputName'];
echo "<br>Input Value: " . $inputValue;
}

if(isset($_GET['id'])){
$getValue = $_GET['id'];
echo "<br>Get Value: " . $getValue;
}
?>

<html>
<head><title>Multiple Forms in One Page</title></head>
<body>

<br>
<a href="index.php">Main Page</a>
<br>
<?php for($i = 0; $i < 3; $i++){ ?>
<form action="index.php?id=<?php echo $id[$i] ?>" method="post" name="formName">
        <textarea name="inputName"></textarea>
        <input type="submit" name="submitName">
</form>
<?php } ?>
</body>
</html>

FOUND THE PROBLEM (BUT STILL NEED FIX)

<script>
    $(function() {
        $('textarea#group-comment').on('keydown', function(e) {
            if(e.keyCode == 13 && !e.shiftKey){
                document.getElementById('group-comment-form').submit();
            }
        });
    });
</script>

I use this script to submit my forms. I don't have a submit button to submit. If I use submit button, everything works perfect but if I use this script above to submit the form, it won't work. What should I do to make the script above work?

SOLUTION After I found where the problem is caused, I created another question to find a fix for the problem.

The answer is here: Solutution

Community
  • 1
  • 1
cyonder
  • 852
  • 1
  • 15
  • 36
  • This logic will create multiple forms. Is that how you want it? Could you not do it using single form ? – Maximus2012 May 01 '15 at 13:44
  • 2
    It is possible to `GET` and `POST` at the same time, but it's awkward and I wouldn't suggest it. How about just using a `hidden` input field to pass whatever else? – Carrie Kendall May 01 '15 at 13:44
  • possible duplicate of http://stackoverflow.com/questions/7954831/i-cant-use-get-and-post-at-the-same-time-in-php – Carrie Kendall May 01 '15 at 13:45
  • Maximus you can imagine the comment form same facebook. You know in facebook it creates comment box for each post. So, I cannot do it in one form. – cyonder May 01 '15 at 13:54
  • Why not give a unique ID to the text area based on pin_id ? – Maximus2012 May 01 '15 at 15:08
  • if I give unique id, how am I gonna reference that textarea in the post? if(isset($_POST["group-comment"])) I use this to reference textarea. How can I receive textarea's unique id? – cyonder May 01 '15 at 15:33

0 Answers0