2016-04-20 6 views
1

Ich habe ein kleines Abstimmungssystem für die Schule gemacht und ich habe ein Problem, wenn eine Frage nicht 4 Antworten hat. Ich möchte das HTML-Formular nur die Schaltflächen mit einem Wert anzeigen. Screenshot of the voting systemTeile des HTML-Formulars ausblenden, wenn Wert = null

Schaltfläche 3 und 4 sind nicht definiert. Nur die Schaltflächen 1 und 2 sollten sichtbar und anklickbar sein.

Das ist mein 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> 

Klingt nicht wie eine komplizierte Sache zu tun, aber ich kann keine Antworten finden Sie hier. Vielen Dank!

Grüße Timo

+0

Vielleicht Angular [ngif Richtlinie] mit (https://docs.angularjs.org/api/ng/directive/ngIf) ? – Hatef

Antwort

3

Verwenden Sie PHP Script

<?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 } ?> 

folgen dem gleichen für alle vier Eingabefelder Wege

+0

Danke, das funktioniert! –

+0

Willkommen ... @TimoSpringer – Kunal

1

Sie haben ein Vielfaches zu überprüfen, es zu tun, könnte man eine Bedingung hinzuzufügen sein Um den Eingang, wie folgt:

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

Oder der CSS Art und Weise:

input[value=""] { display: none; } 

See it here

0

Sie können PHP-Bedingungen wie folgt verwenden die letzten beiden Tasten zu verstecken, wenn sie nicht gesetzt.

<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> 

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

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

</form> 
0

Sie tun können, es zu benutzen, wenn die Bedingung als

<?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 } ?> 
0
folgen

Dies sollte funktionieren:

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

     <div class="form-group"> 
      <?php 
      if($voting->a <> '') { echo '<input type="submit" name="a" id="a" value="'.$voting->a.'"/>';} 
      ?> 
     </div> 

     <div class="form-group"> 
      <?php 
      if($voting->b <> '') { echo '<input type="submit" name="b" id="b" value="'.$voting->b.'"/>';} 
      ?> 
     </div> 

     <div class="form-group"> 
      <?php 
      if($voting->c <> '') { echo '<input type="submit" name="c" id="c" value="'.$voting->c.'"/>';} 
      ?> 
     </div> 

     <div class="form-group"> 
      <?php 
      if($voting->d <> '') { echo '<input type="submit" name="d" id="d" value="'.$voting->d.'"/>';} 
      ?> 
     </div> 

    </form> 
0

versuchen diese

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

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

 
     <div class="form-group"> 
 
      <?php 
 
      if($voting->b != '') { echo '<input type="submit" name="b" id="b" value="'.$voting->b.'"/>';} 
 
      ?> 
 
     </div> 
 

 
     <div class="form-group"> 
 
      <?php 
 
      if($voting->c != '') { echo '<input type="submit" name="c" id="c" value="'.$voting->c.'"/>';} 
 
      ?> 
 
     </div> 
 

 
     <div class="form-group"> 
 
      <?php 
 
      if($voting->d != '') { echo '<input type="submit" name="d" id="d" value="'.$voting->d.'"/>';} 
 
      ?> 
 
     </div> 
 

 
    </form>

0

Ihre Klassenstruktur im Allgemeinen nicht sehr gut, aber für Ihr Beispiel

<form role="form" class="form-inlinecy" action="VotingVoting.php" method="post"> 
<?php 
foreach (['a','b','c','d'] as $id) { 
    if (empty($voting->$id)) continue;?> 
    <div class="form-group"> 
     <input type="submit" name="<?php echo $id;?>" id="<?php echo $id;?>" value="<?php echo $voting->$id; ?>"/> 
    </div> 
<?php } ?> 
</form> 
Verwandte Themen