I want a button to show up if an if statement in php is true. To my knowledge you can't use html in php, so how do i do it?
This is the code:
<!-- 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 -->
Tried to do it this way. leave a gap in the php code, and catch the last accolade from the if isset construction in a separate php part, but now it takes the if always for 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 -->
Any help would be really appreciated, thanks is advance! i've searched thouroughly, but couldn't find a similar question. Please redirect me if there are similar qustions with answers. PS sorry for my bad english, but i'm a dutchman..
<!-- 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 -->
You can output it by making a whole html block php-dependent:
$test = 1;
if ($test) { ?>
<button>Good</button>
<?php }
else { ?>
<button>Bad</button>
<?php }
Will output the button when the condition is 1. There's another method, however not normally recommended as it makes your code messier:
$test = 1;
if ($test)
echo "<button>Good</button>";
else
echo "<button>Bad</button>";
You can switch between HTML and PHP any time you want by opening <?php
and closing ?>
<?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
}
}
?>
Indentation and alternative control statements can be prettier
<!-- 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 -->
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.