Timo Springer Timo Springer - 7 months ago 10
HTML Question

Hide parts of HTML form when value = null

I made a little voting system for school and I have a problem when a question doesn't have 4 answers.
I want the html form to show only the buttons with a value.
Screenshot of the voting system

Button 3 and 4 are not defined. Only button 1 and 2 should be visible and clickable.

That's my code:

<form role="form" class="form-inlinecy" action="VotingVoting.php" method="post">

<div class="form-group">
<input type="submit" name="a" id="a" value="<?php echo $voting->a ?>"/>
</div>

<div class="form-group">
<input type="submit" name="b" id="b" value="<?php echo $voting->b ?>"/>
</div>

<div class="form-group">
<input type="submit" name="c" id="c" value="<?php echo $voting->c ?>"/>
</div>

<div class="form-group">
<input type="submit" name="d" id="d" value="<?php echo $voting->d ?>"/>
</div>

</form>


Doesn't sound like a complicated thing to do, but I can't find answers here. Thanks so much!

Greetings
Timo

Answer

Use PHP Script to check

  <?php  if(isset($voting->a) && !empty($voting->a))
    { ?>
       <div class="form-group">
          <input type="submit" name="a" id="a" value="<?php echo $voting->a ?>"/>
       </div>
    <?php } ?>

follow the same for all four input fields