我试图文章ID本身文件中的PHP。但它张贴什么。此代码我尝试
//if can it should echo 1 and point 232
<?php
if ($_POST['submit'] == 'winners') {
$a = $_GET['A'];
echo $a;
$point = $_GET['POIN'];
echo $point;
}
?>
<form enctype="multipart/form-data" method="post" style="width:auto;">
<div class="box">
<span class='odometer' id="timespan" name="timespan">232</span>
</div>
<input class="process" name="submit" type="submit" id="submit" value="winners" onclick="location.href='reward-pollingx.php?A=1&POIN='+document.getElementById('timespan').innerHTML'">
</form>
你想用JavaScript来获得PHP中跨度值。尝试是这样的:
<?php
$a = isset( $_GET['A'] ) ? $_GET['A'] : '';
echo $a;
$point = isset( $_GET['POIN'] ) ? $_GET['POIN'] : '';
echo $point;
?>
<form enctype="multipart/form-data" method="post" style="width:auto;">
<div class="box">
<span class='odometer' id="timespan" name="timespan">232</span>
</div>
<input
class="process"
name="submit"
type="submit"
id="submit"
value="winners"
onclick="window.location='reward-pollingx.php?A=1&POIN='+document.getElementById('timespan').innerHTML;return false;"
>
</form>
如果你试图通过参数,如查询字符串,你不需要使用的一种形式。
因为您配置表单发送POST请求,您可以通过查询字符串参数隐藏式的输入值。测试如下
<form action="reward-pollingx.php" enctype="multipart/form-data" method="post" style="width:auto;">
<input type="hidden" name="A" value="1">
<input type="hidden" name="POIN" value="">
<input type="hidden" name="submit" value="winners">
<div class="box">
<span class='odometer' id="timespan" name="timespan">232</span>
</div>
<input class="process" name="submit" type="submit" id="submit" value="winners">
</form>
<script>
document.querySelector('input[name=POIN]').value = document.getElementById('timespan').innerHTML;
</script>
你的PHP代码应该改变使用$ _POST而不是$ _GET
<?php
if ($_POST['submit'] === 'winners') {
$a = $_POST['A'];
echo $a;
$point = $_POST['POIN'];
echo $point;
}
或者使用查询字符串参数传递给PHP脚本
<a href="reward-pollingx.php?submit=winners&A=1&POIN=...">Submit</a>
而PHP
if ($_GET['submit'] === 'winners') {
$a = $_GET['A'];
echo $a;
$point = $_GET['POIN'];
echo $point;
}
要构建查询字符串,因为你需要从视图中获取信息,你可能需要动态地生成它
如果您需要将表格提交到自身,您可以使用
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" ....
或者您可以使用:
<form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="POST" ....