0

Ok so what I though should be pretty easy has got me going crazy. I cannot figure out a conditional statement to get this to work the way I need it to.

This is my first page index.html which is a form and will post to the next page below

<div id="Includes_area">
<input type="text" id="Includes_1" name="Includes_1" />
<input type="text" id="Includes_1" name="Includes_2" />
<input type="text" id="Includes_1" name="Includes_3" />
<input type="text" id="Includes_1" name="Includes_4" />
<input type="text" id="Includes_1" name="Includes_5" />
</div>

This is the page being posted to, created.php. All I am trying to do is have the created.php only show the fields that have had entry, and if none have had entry to not show any part of the Divs or anything.

<div>
<h3>Includes</h3>
<div>
<div>
  <ul>
    <li> <?php echo("$Includes_1")?></li>
    <li> <?php echo("$Includes_2")?></li>
    <li> <?php echo("$Includes_3")?></li>
    <li> <?php echo("$Includes_4")?></li>
    <li> <?php echo("$Includes_5")?></li>
  </ul>
</div>

I would appreciate any help on this, thank you !

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by pritaeas
0

You need to use the $_POST array.

<?php
$Includes_1 = isset($_POST['Includes_1']) ? $_POST['Includes_1'] : '';
$Includes_2 = isset($_POST['Includes_2']) ? $_POST['Includes_2'] : '';
$Includes_3 = isset($_POST['Includes_3']) ? $_POST['Includes_3'] : '';
$Includes_4 = isset($_POST['Includes_4']) ? $_POST['Includes_4'] : '';
$Includes_5 = isset($_POST['Includes_5']) ? $_POST['Includes_5'] : '';

$NoValues = empty($Includes_1) and empty($Includes_2) and empty($Includes_3) and empty($Includes_4) and empty($Includes_5);

if (! $NoValues) // at least one has a value
{
  echo '<div><h3>Includes</h3></div><div><ul>';

  if (!empty($Includes_1))
    echo "<li>$Includes_1</li>";

  if (!empty($Includes_2))
    echo "<li>$Includes_2</li>";

  if (!empty($Includes_3))
    echo "<li>$Includes_3</li>";

  if (!empty($Includes_4))
    echo "<li>$Includes_4</li>";

  if (!empty($Includes_5))
    echo "<li>$Includes_5</li>";

  echo '</ul></div>';
}
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.