Reputation: 13
I am trying pass a parameter in action tag in form, just the way I am doing in href tag but this isn't working can I know why? or should I just use a href tag in form, will that overwrite action in form? Here is my code:
<!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>
Upvotes: 1
Views: 76
Reputation: 7776
1) As you already creating link based on condition then you can directly echo that variable inside markup. e.g.
<?php echo $rep; ?>
2) Instead of passing html in form action just you pass that script name. e.g
newblocktryteacher.php?a=somename or newblocktrypupil.php?a=somename
Based on these two points your code will be
<!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>
Upvotes: 1
Reputation: 8033
Your $blk
is not a valid action form, because it's a <a>
tag(link). So, $blk
should be newblocktrypupil.php?a=$name'
instead.
Upvotes: 0
Reputation: 2030
Your $blk
isn't formatted in a way proper for <form>
:
$blk = "<a href='newblocktryteacher.php?a=$name'>Block this site</a>";
<FORM action = <?php echo $blk; ?> method ="POST";>
Assuming $name
is bob
in this example:
<FORM action = <a href='newblocktryteacher.php?a=bob'>Block this site</a> method ="POST";>
As you can see, this is not correct. All you need is the URL itself. Also, remove the semicolon after "POST"
.
Upvotes: 0