如果php中的if语句为true,我希望显示一个按钮。据我所知,你不能在php中使用html,那么我该怎么做呢?
这是代码:
<!-- begin of form -->
<form method="post" action="something.php">
<input type="text" name="something" required="required" />
<input type="submit" name="submit" value="Submit">
</form>
<?php
if(isset($_POST["submit"]))
{
$something = $_POST["something"];
if($something == "blabla")
{echo"yes blabla";}
//this is where i would like to have a button
<form method="link" action="someurl.com">
<input type="submit" value="Go">
</form>
// end button
} ?>
<!-- end of form -->
试着这样做。在php代码中留下一个空白,并在单独的php部分中获得if-iset构造的最后一个荣誉,但现在它将if-always作为true。
<!-- begin of form -->
<form method="post" action="something.php">
<input type="text" name="something" required="required" />
<input type="submit" name="submit" value="Submit">
</form>
<?php
if(isset($_POST["submit"]))
{
$something = $_POST["something"];
if($something == "blabla")
{echo"yes blabla";}
?>
//this is where i would like to have a button
<form method="link" action="someurl.com">
<input type="submit" value="Go">
</form>
// end button
<?php } ?>
<!-- end of form -->
如有任何帮助,我们将不胜感激,谢谢!我找了很多遍,却找不到类似的问题。如果有类似的问题和答案,请重定向我。PS很抱歉我英语不好,但我是荷兰人。。
<!-- begin of form -->
<form method="post" action="something.php">
<input type="text" name="something" required="required" />
<input type="submit" name="submit" value="Submit">
</form>
<?php
if(isset($_POST["submit"]))
{
$something = $_POST["something"];
if($something == "blabla")
{echo"yes blabla";
?>
//this is where i would like to have a button
<form method="link" action="someurl.com">
<input type="submit" value="Go">
</form>
// end button
<?php } ?>
<!-- end of form -->
您可以通过使整个html块依赖php来输出它:
$test = 1;
if ($test) { ?>
<button>Good</button>
<?php }
else { ?>
<button>Bad</button>
<?php }
当条件为1时,将输出按钮。还有另一种方法,但通常不推荐使用,因为它会使代码更加混乱:
$test = 1;
if ($test)
echo "<button>Good</button>";
else
echo "<button>Bad</button>";
您可以通过打开<?php
和关闭?>
随时在HTML和PHP之间切换
<?php
if(isset($_POST["submit"]))
{
$something = $_POST["something"];
if($something == "blabla")
{
echo "yes blabla";
?>
<form method="link" action="someurl.com">
<input type="submit" value="Go">
</form>
<?php
}
}
?>
缩进和替代控制语句可能更漂亮
<!-- begin of form -->
<form method="post" action="something.php">
<input type="text" name="something" required="required" />
<input type="submit" name="submit" value="Submit">
</form>
<?php
if(isset($_POST["submit"])):
$something = $_POST["something"];
if($something == "blabla"):?>
yes blabla
<?php endif;?>
//this is where i would like to have a button
<form method="link" action="someurl.com">
<input type="submit" value="Go">
</form>
// end button
<?php endif; ?>
<!-- end of form -->