English 中文(简体)
php的形式不是与隐蔽领域合作
原标题:php form not working with hidden field

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?

感谢任何帮助。

问题回答

该法典可能有所帮助。

<?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>
document.getElementById("hidden_logout_id").value

您没有就此一线采取任何行动,或是把其价值分配给变数。

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

愿你帮助。

展望

hidden_logout_name 

而不是

hidden_logout_id

因此,你的价值在于

$_POST[ hidden_logout_name ]




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签