gpt4 book ai didi

javascript - 使用自动提交过帐值不起作用

转载 作者:行者123 更新时间:2023-11-28 01:39:46 25 4
gpt4 key购买 nike

我有一个来自另一个页面的帖子值并发布到index2.php。我想使用自动提交脚本再次将该值发布到 autosubmit.php 。但为什么不起作用?

这是我的代码

index2.php

<?php
$mysqli = new mysqli("localhost", "root", "", "app");
if (isset($_POST['submit'])) {
$drop=$_POST['drop'];
$tier_two=$_POST['tier_two'];

echo'
<form method="post" action="autosubmitform.php" id="dateForm" name="dateForm">
<input name="drop" type="" value="'.$drop.'" style="background-color:blue;"><input name="tier_two" type="" value="'.$tier_two.'">
<input type="submit" name="editsubmit">
</form>';

echo'<script type="text/javascript">
document.getElementById("dateForm").submit(); // SUBMIT FORM
</script>';

}
?>

自动提交表单.php

<?php
$mysqli = new mysqli("localhost", "root", "", "app");
if (isset($_POST['editsubmit'])) {
$drop=$_POST['drop'];
$tier_two=$_POST['tier_two'];

echo $drop; echo $tier_two;
}
echo'
<input name="drop" type="" value="'.$drop.'" style="background-color:red;"><input name="tier_two" type="" value="'.$tier_two.'">
<input type="submit" name="editsubmit">';
?>

最佳答案

代码的更改

   /*
if you submit your form through javascript your button value is not submited
so you have to click that by javascript to submit it value
*/

<script type="text/javascript">

document.getElementsByName("editsubmit")[0].click(); // SUBMIT FORM
</script>

还要将您的 echo 代码移至 php 内部,因为如果它不进入 if 内部,则您的变量 $drop$tier_two 仍处于未定义状态在 if

之外的 echo 语句中
if (isset($_POST['editsubmit'])) {
$drop=$_POST['drop'];
$tier_two=$_POST['tier_two'];

echo $drop;
echo $tier_two;
echo'
<input name="drop" type="text" value="'.$drop.'" style="background-color:red;"><input name="tier_two" type="text" value="'.$tier_two.'">
<input type="submit" name="editsubmit">';
}

上述 PHP 代码的替代解决方案

$drop = ''; 
$tier_two = '';
if (isset($_POST['editsubmit'])) {
$drop=$_POST['drop'];
$tier_two=$_POST['tier_two'];

echo $drop;
echo $tier_two;

}
echo'
<input name="drop" type="text" value="'.$drop.'" style="background-color:red;"><input name="tier_two" type="text" value="'.$tier_two.'">
<input type="submit" name="editsubmit">';

关于javascript - 使用自动提交过帐值不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21059427/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com