Why is $_POST always null?

Discussion in 'PHP' started by Imozeb, Jul 21, 2010.

  1. #1
    Why is $_POST always null?

    php CODE:
    
    if(isset($_POST['addFriend_name']))
    {
    echo('TEST');
    }
    
    Code (markup):
    js CODE:
    
    function addFriend(name) {
    		//set vars
    		document.getElementById('addFriend_name').value = name;
    		//refresh screen
    		document.getElementById('addFriend_form').submit();
    
    }
    
    Code (markup):
    html CODE:
    
    <div style="display:none;">
    								<form id="addFriend_form" method="post" action="http://www.foreverplaying.com/script/members/member_test.php">
    									<p>
    										<input type="hidden" id="addFriend_name" name="addFriend_name" />
    									</p>
    								</form>
    							</div>
    
    Code (markup):

    If you the source code would help the page is: http://www.foreverplaying.com/script/members/member_glock77.php


    Please help. I've been working on this problem for an hour and I still can't see whats wrong? Mabye some fresh eyes might see the problem. If you need anymore info tell me and I'll post it.

    Thanks.
     
    Imozeb, Jul 21, 2010 IP
  2. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #2
    Because it doesn't make any sense. "addFriend_name" type should be text, not hidden. Try this:
    
    <div style="display:none;">
    								<form id="addFriend_form" method="post" action="http://www.foreverplaying.com/script/members/member_test.php">
    									<p>
    										<input type="text" id="addFriend_name" name="addFriend_name" />
    									</p>
    								</form>
    							</div>
    
    HTML:
    Here's a standalone example of how $_POST and form works together:
    
    <?php
    echo "<form action='' method='post'>";
    echo "<input type='text' name='addFriend_name' />";
    echo "<input type='submit' value='lol' />";
    
    if(isset($_POST['addFriend_name'])) {
    echo $_POST['addFriend_name'];
    }
    ?> 
    
    PHP:
     
    Rainulf, Jul 21, 2010 IP
  3. Imozeb

    Imozeb Peon

    Messages:
    666
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    It is still not working. Any more ideas? Thanks.
     
    Imozeb, Jul 22, 2010 IP
  4. ssmm987

    ssmm987 Member

    Messages:
    180
    Likes Received:
    4
    Best Answers:
    3
    Trophy Points:
    43
    #4
    First of all, I don't get your javascript piece, it sets a value, and than refreshes the page without sending that value... I don't know why you use it either. Just skip the javascript part, ant together with rainulf's script it would work. If it doesn't, could you please give the outcome of print_r($_POST)
     
    ssmm987, Jul 22, 2010 IP
  5. Bohra

    Bohra Prominent Member

    Messages:
    12,573
    Likes Received:
    537
    Best Answers:
    0
    Trophy Points:
    310
    #5
    is php installed properly ??
     
    Bohra, Jul 22, 2010 IP
  6. Imozeb

    Imozeb Peon

    Messages:
    666
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Yes php is installed properly. What do you mean it doesn't send the value? I need the javascript part because it is part of a function which makes the hidden field value a name (could be any name) and then submits it to the server for processing. I don't get why the $_POST var is always null.
     
    Imozeb, Jul 22, 2010 IP
  7. Bohra

    Bohra Prominent Member

    Messages:
    12,573
    Likes Received:
    537
    Best Answers:
    0
    Trophy Points:
    310
    #7
    can you try this and see if it works

    <?php
    echo "<form action='' method='post'>";
    echo "<input type='text' name='addFriend_name' value='test' />";
    echo "<input type='submit' value='lol' />";

    if(isset($_POST['addFriend_name'])) {
    echo $_POST['addFriend_name'];
    }
    ?>
     
    Bohra, Jul 22, 2010 IP
  8. Imozeb

    Imozeb Peon

    Messages:
    666
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #8
    The file you gave me works (tested in its own file) but my full script still doesn't work. What I don't understand is I have another form on the same page with about 7 fields and that form works (It uses the same format). The form which is not working is just above the other form but that shouldn't matter. The php functions are at the top of the page.

    The main problem is still not working.
     
    Last edited: Jul 22, 2010
    Imozeb, Jul 22, 2010 IP
  9. Imozeb

    Imozeb Peon

    Messages:
    666
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Could someone help me with my problem. It is urgent.
     
    Imozeb, Jul 22, 2010 IP
  10. Zeh.

    Zeh. Peon

    Messages:
    57
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Where and how do you call addFriend() ?
     
    Zeh., Jul 22, 2010 IP
  11. Imozeb

    Imozeb Peon

    Messages:
    666
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Never mind I got it. the action was to a url with capitals.
     
    Last edited: Jul 23, 2010
    Imozeb, Jul 23, 2010 IP