How to format text in php when we have two or more options

I am trying to make a simple script that allows you to format text and send it.

Here is the form:

<html>
<head>
<title>
</title>
</head>
<body>
<form method="post" action="step2.php">
<input type="text" name="text"  /><br>
Red<input type="radio" name="Red" /> <br>
15px<input type="radio" name="15" /> <br>
<input type="submit" name="submit"/>
</form>
</body>
</html>

and in stage 2.php at this stage I show the results when 2 options are selected. I try to show the results when only “Red” is selected, when only “15px” is selected, when both are selected and when nothing is selected. Here is my script at the moment:

<?php
if (isset($_POST['Red']) && isset($_POST['15']) ) {
echo "<font size='15px' color=red>";
echo $_POST['text'];
echo "</font>";
}

?>

I managed Thanks for the answers! the secret was empty ($ varname), here is the code

<?php
if (isset($_POST['Red']) && isset($_POST['15']) ) {
echo "<font size='15px' color=red>";
echo $_POST['text'];
echo "</font>";
}

if (empty($_POST['Red']) && isset($_POST['15']) ) {
echo "<font size='15px'>";
echo $_POST['text'];
echo "</font>";
}

if (isset($_POST['Red']) && empty($_POST['15']) ) {
echo "<font color=red>";
echo $_POST['text'];
echo "</font>";
}

if (empty($_POST['Red']) && empty($_POST['15']) ) {
echo $_POST['text'];
}
?>
+5
source share
3 answers

, - XML/DOM

:

$attrs='';
if(isset($_POST['Red']))
    $attrs.='color=red';
if(isset($_POST['15']))
    $attrs.='size="15px";

, , <font> .

+1

Radiobuttons , ,

<html>
<head>
<title>
</title>
</head>
<body>
<form method="post" action="step2.php">
<input type="text" name="text"  /><br>
Red<input type="checkbox" name="Red" value="Red" /> <br>
15px<input type="checkbox" name="px15" value="15" /> <br>
<input type="submit" name="submit"/>
</form>
</body>
</html>

step2.php

<?php
if (isset($_POST['Red']) && isset($_POST['px15']) ) {
echo "<font size='15px' color=red>";
echo $_POST['text'];
echo "</font>";
}

?>
+1

Here is the solution :):

    <?php
if (isset($_POST['Red']) && isset($_POST['15']) ) {
echo "<font size='15px' color=red>";
echo $_POST['text'];
echo "</font>";
}

if (empty($_POST['Red']) && isset($_POST['15']) ) {
echo "<font size='15px'>";
echo $_POST['text'];
echo "</font>";
}

if (isset($_POST['Red']) && empty($_POST['15']) ) {
echo "<font color=red>";
echo $_POST['text'];
echo "</font>";
}

if (empty($_POST['Red']) && empty($_POST['15']) ) {
echo $_POST['text'];
}
?>
0
source

All Articles