Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation cannot get $_POST value

    i have this script which sends the input from the forms to comments_ajax.php
    it posts ID (msg_id) and comment but not 'type'... i also wanted to add fields but i dont know how, considering i failed when i added 'type'


    Code:
    $('.comment_button').live("click",function() 
    {
    
    var ID = $(this).attr("id");
    
    var comment= $("#ctextarea"+ID).val();
    var type= $("#type"+ID).val();
    var dataString = 'comment='+ comment + '&msg_id=' + ID + '&type=' + type;
    
    if(comment=='')
    {
    alert("Please Enter Comment Text");
    }
    else
    {
    $.ajax({
    type: "POST",
    url: "extra/comment_ajax.php",
    data: dataString,
    cache: false,
    success: function(html){
    $("#commentload"+ID).append(html);
    $("#ctextarea"+ID).val('');
    $("#ctextarea"+ID).focus();
     }
     });
    }
    return false;
    });

    this is the form
    Code:
    <form method=\"post\" action=\"\">
    
    <input type='text' name=\"comment\" class=\"comment\" maxlength=\"200\"  id=\"ctextarea$msg_id\" style=\"float:left;width:400px;padding:1px\" >
    <input type='hidden' name=\"type\" class=\"type\" maxlength=\"200\"  id=\"type$msg_id\" \" >
    <input type=\"submit\"  value=\" Comment \"  id=\"$msg_id\" class=\"comment_button small green awesome\" style=\"float:left;padding:2px\"/>
    </form>
    and this is comment_ajax.php
    Code:
    <?php
    echo "$_POST[type] $_POST[comment] $_POST[msg_id]";?>

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    this is the form
    I'd recommend you to validate your html source(taken from browser's view source option) first, and eliminate the errors in your markup, if any.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Regular Coder
    Join Date
    Jul 2010
    Location
    Sheffield
    Posts
    824
    Thanks
    93
    Thanked 18 Times in 18 Posts
    The PHP is wrong, to echo the post variables you need to put

    PHP Code:
    echo "Type: ".$_POST[type].". Comment: ".$_POST[comment].". Msg ID: ".$_POST[msg_id]."."
    What you had would just echo $_POST[type] $_POST[comment] $_POST[msg_id]


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •