0

Not sure but this may be a bug in php. Here is my dummy code.

<script language="javascript">
function fb_logout() {
document.getElementById("hidden_logout_id").value
alert(document.getElementById("hidden_logout_id").value);
document.getElementById("form_1").submit();
}
</script>

echo "<form id=\"form_1\" action=\"" . $_SERVER['PHP_SELF'] . "\" method=\"post\">";
echo "<input type=\"hidden\" id=\"hidden_logout_id\" name=\"hidden_logout_name\" value=\"1\"/>";
echo "<input type=\"text\" id=\"h_logout2\" name=\"h_logout2\" value=\"1\"/>";    
echo "</form>";
var_dump($_POST);
echo "<span onclick=\"fb_logout();\">Logout</span>";

When doing a post trough the click on the span the values of the hidden and the text inside the form do not get posted: var_dump($_POST) shows an empty variable. But it's strange that if I remove the hidden from the form (or I just place it outside the form) it works and it passes in the $_POST the value of the input text remaining in the form. Does this has to do with that the hidden is modified from an event outside the form?

Any help is appreciated.

4
  • "Not sure but this may be a bug in php" Nope, what makes you think so? What browser do you use? Given example works for me in Chrome.
    – CodeCaster
    May 2, 2012 at 10:52
  • Works for me too in Firefox. The problem is somewhere else. May 2, 2012 at 10:56
  • I get the same wierd behaviour in internet explorer and Firefox. It sometimes works imediately after changing the name or id of the hidden field. But as I said in the question if I remove the hidden from the form (or i put it outside) it shows some $_POST data posted. Otherwise it $_POST is empty.
    – Paul Rusu
    May 2, 2012 at 10:57
  • could it be that i reach a limit of memory for the SESSION and the POST variables. I do not have any post variables other than the 2 above but I have some in the SESSION.
    – Paul Rusu
    May 2, 2012 at 11:06

3 Answers 3

2

This code may help..

<?php
    if(isset($_POST['hidden_logout_name'])) var_dump($_POST);   
?>
<script language="javascript">
function fb_logout() {    
    alert(document.getElementById("hidden_logout_id").value);
    document.getElementById("hidden_logout_id").value = "hidden_logout_value";
    document.getElementById("form_1").submit();
}
</script>

<form id="form_1" action="" method="post">
    <input type="hidden" id="hidden_logout_id" name="hidden_logout_name" value=""/>
    <input type="text" id="h_logout2" name="h_logout2" value="1"/>
</form>
<button onclick="fb_logout();">Logout</button>
1
document.getElementById("hidden_logout_id").value

you have not done any action for this line either assign value to this or assign its value to variable.

var logout_value=document.getElementById("hidden_logout_id");
alert(logout_value.value);
document.getElementById("form_1").submit();

May this help you.

0

look for the

hidden_logout_name 

instead of

hidden_logout_id

so your value is in the

$_POST['hidden_logout_name']

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.