2017-10-04 82 views
0

我試圖讓我可以通過從一個或兩個複選框中選擇它來決定名稱和小時的表格。例如,如果我有一個新的名字和小時,我可以通過複選框選擇它是在「標準」還是「高級」或兩者中進行選擇。如何將數據插入選定複選框中的表中?

#myform .plus, .minus { 
 
    text-decoration: none; 
 
    color: #fff; 
 
    background-color: #fdd818; 
 
    text-align: center; 
 
    letter-spacing: .5px; 
 
    -webkit-transition: .2s ease-out; 
 
    transition: .2s ease-out; 
 
    cursor: pointer; 
 
} 
 

 
.collapsible-header{ 
 
    color: #ffffff; 
 
} 
 

 

 

 
.row{ 
 
\t margin: 0; \t 
 
\t width: 100%; 
 
} 
 
.uren{ 
 
\t display: -webkit-inline-box; 
 
    padding-left: 10px; 
 
    padding-right: 10px; 
 
} 
 
.btn { 
 
    -webkit-border-radius: 28; 
 
    -moz-border-radius: 28; 
 
    border-radius: 28px; 
 
    font-family: Arial; 
 
    color: #ffffff; 
 
    font-size: 20px; 
 
    background: #ffcc00; 
 
    padding: 5px 10px 5px 10px; 
 
    text-decoration: none; 
 
} 
 
.btn:hover { 
 
    background: #dbaf00; 
 
    text-decoration: none; 
 
} 
 

 

 
/* Pop up */ 
 
.letspop{ 
 
    background-color: #fff; 
 
    width: 120px; 
 
    display: block; 
 
    margin: 5% auto; 
 
    padding: 20px; 
 
    position: relative; 
 
    text-align: center; 
 
    float: right; 
 
    margin-right: 20px; 
 
    margin-top: 0px; 
 
} 
 
.letspop:hover{ 
 
    cursor: pointer; 
 
} 
 
.overlay{ 
 
    display: none; /* Default Hidden */ 
 
    position: fixed; 
 
    left: 0; 
 
    top: 0; 
 
    z-index: 1; 
 
    background-color: rgba(0,0,0,0.6); 
 
    height: 100%; 
 
    width: 100%; 
 
} 
 
.popup{ 
 
    display: none; /* Default Hidden */ 
 
    position: fixed; 
 
    left: 50%; 
 
    top: 5%; 
 
    z-index: 2; 
 
    background-color: #fff; 
 
    height: 450px; 
 
    width: 300px; 
 
    overflow: hidden; 
 
    padding: 40px; 
 
    transform: translate(-50%, 0); 
 
} 
 
#new_module{ 
 
    width: 195px; 
 
} 
 

 
h1, h2{ 
 
    color: steelblue ; 
 
    font-family: sans-serif; 
 
    text-align: center; 
 
    text-transform: uppercase; 
 
    line-height: 1; 
 
} 
 
h2{ 
 
    color: dodgerblue ; 
 
} 
 
small{ 
 
    color: #444 ; 
 
    font-size:0.4em; 
 
    display: block; 
 
    margin: 0.2rem auto 0; 
 
} 
 
.close{ 
 
    position: absolute; 
 
    top: 8px; 
 
    right: 8px; 
 
    display: block; 
 
    color: #666666; 
 
    font-family: sans-serif; 
 
} 
 
.close:hover{ 
 
    cursor: pointer; 
 
    color: #444444; 
 
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css" rel="stylesheet"/> 
 
    <form action="#" method="POST"> 
 
     <div class="row"> 
 
     <div class="input-field col s6"> 
 
      <input id="new_module" type="text" class="validate"> 
 
      <label class="active" for="new_module">Name</label> 
 
     </div> 
 
     </div> 
 
     <form action="#"> 
 
     <p class="range-field"> 
 
      <input type="range" id="test" min="0" max="20" /> 
 
     </p> 
 
     </form> 
 
     <p> 
 
     <input type="checkbox" class="filled-in" id="standard"/> 
 
     <label for="standard">Standard</label> 
 
     </p> 
 
     <p> 
 
     <input type="checkbox" class="filled-in" id="advanced"/> 
 
     <label for="advanced">Advanced</label> 
 
     </p>  
 
     <hr> 
 
     <button class="btn waves-effect waves-light" type="submit" name="action"> 
 
      <i class="material-icons right">send</i> 
 
     </button> 
 
     <div class="close">X</div> 
 
    </form>

+0

你需要設置'action'形式標籤。並在該文件中,您需要執行處理。 –

回答

0

您需要設置名稱爲HTML元素提交到服務器。 嘗試以下變化:

<form action="checkbox.php" method="post"> 
     <p> 
      <input type="checkbox" class="filled-in" id="standard" name="chk[]" value="standard"/> 
      <label for="standard">Standard</label> 
      </p> 
      <p> 
      <input type="checkbox" class="filled-in" id="advanced" name="chk[]" value="advanced"/> 
      <label for="advanced">Advanced</label> 
      </p> 
      <input type="submit" /> 
    </form> 

,並嘗試下面的PHP代碼找到選擇複選框

foreach($_POST['chk'] as $key => $chk){ 
    if($chk == 'standard'){ 
     // do some code 
    } 
if($chk == 'advanced'){ 
     // do some code 
    } 
} 
相關問題