gpt4 book ai didi

javascript - 在html之间传递变量(php)

转载 作者:行者123 更新时间:2023-11-28 17:07:53 26 4
gpt4 key购买 nike

我正在尝试以表单的形式在 action 标签中传递一个参数,就像我在 href 标签中所做的那样,但这不起作用,我知道为什么吗?或者我应该只在表单中使用 href 标签,这会覆盖表单中的操作吗?这是我的代码:

<!DOCTYPE html>
<html lang="en">
<?php
$ty=$_GET['param'];
$name=$_GET['param1'];
if($ty=='teacher')
{
$web = "<a href='teacherrepute.php?a=$name'>My repute score</a>";
$rep = "<a href='teacherreported.php?a=$name'>My reported sites</a>";
$blk = "<a href='newblocktryteacher.php?a=$name'>Block this site</a>";
$unblk = "<a href='newtryunblockteacher.php?a=$name>Unblock this site";
}
else
{
$web = "<a href='pupilrepute.php?a=$name'>My repute score</a>";
$rep = "<a href='pupilreported.php?a=$name'>My reported sites</a>";
$blk = "<a href='newblocktrypupil.php?a=$name'>Block this site</a>";
$unblk = "<a href='newtryunblockpupil.php?a=$name>Unblock this site";
}
// $type=$_GET['param2'];
$courseA='A';
$courseB='B';
?>
<body>
<a href="reporttable.html"><?php echo $rep; ?></a>
<FORM action = <?php echo $blk; ?> method ="POST";>
Block : <input type ="text" name = "url" /></br>
<br>
<input type="submit" value="block" />
<br>
</FORM>
</body>
</html>

最佳答案

1) 由于您已经根据条件创建了链接,因此您可以直接在标记中回显该变量。例如

 <?php echo $rep; ?>

2) 只需传递脚本名称,而不是在表单操作中传递 html。例如

newblocktryteacher.php?a=somename or newblocktrypupil.php?a=somename

基于这两点你的代码将是

<!DOCTYPE html>
<html lang="en">
<?php
$ty=$_GET['param'];
$name=$_GET['param1'];
if($ty=='teacher')
{
$web = "<a href='teacherrepute.php?a=$name'>My repute score</a>";
$rep = "<a href='teacherreported.php?a=$name'>My reported sites</a>";
$blk = "newblocktryteacher.php?a=$name";
$unblk = "<a href='newtryunblockteacher.php?a=$name>Unblock this site";
}
else
{
$web = "<a href='pupilrepute.php?a=$name'>My repute score</a>";
$rep = "<a href='pupilreported.php?a=$name'>My reported sites</a>";
$blk = "newblocktrypupil.php?a=$name";
$unblk = "<a href='newtryunblockpupil.php?a=$name>Unblock this site</a>";
}
// $type=$_GET['param2'];
$courseA='A';
$courseB='B';
?>
<body>

<?php echo $rep; ?>
<form action="<?php echo $blk; ?>" method="POST">
Block : <input type="text" name="url" /></br>
<br>
<input type="submit" value="block" />
<br>
</form>
</body>
</html>

关于javascript - 在html之间传递变量(php),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29901613/

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