2014-02-27 49 views
0

我創建一個包含多個複選框HTML表單... 這裏是我的代碼HTML複選框不給值要PHP

形式

<form enctype="multipart/form-data" action="processstart.php" method="post" class="wpcf7-form"> 
    <div class="form-row"> 
    <span class="label--input-group">Services you require</span> 
    <span class="wpcf7-form-control-wrap services"> 
     <span class="wpcf7-form-control wpcf7-checkbox check-group-input"> 
     <span class="wpcf7-list-item"> 
      <label> 
      <input type="checkbox" name="services[]" value="Branding" />&nbsp;<span class="wpcf7-list-item-label">Branding</span> 
      </label> 
     </span> 
     <span class="wpcf7-list-item"> 
      <label> 
      <input type="checkbox" name="services[]" value="Design" />&nbsp;<span class="wpcf7-list-item-label">Design</span> 
      </label> 
     </span> 
     <span class="wpcf7-list-item"> 
      <label> 
      <input type="checkbox" name="services[]" value="Other" />&nbsp;<span class="wpcf7-list-item-label">Other</span> 
      </label> 
     </span> 
     <span class="wpcf7-list-item"> 
      <label> 
      <input type="checkbox" name="services[]" value="Development" />&nbsp;<span class="wpcf7-list-item-label">Development</span> 
      </label> 
     </span> 
     <span class="wpcf7-list-item"> 
      <label> 
      <input type="checkbox" name="services[]" value="Illustration" />&nbsp;<span class="wpcf7-list-item-label">Illustration</span> 
      </label> 
     </span> 
     </span> 
    </span> 
    </div> 
</form> 

這裏是processstart.php

<?php 
    if(isset($_POST['services'])) { 
    foreach($_POST['services'] as $services) { 
     echo $services; 
    } 
    } 
?> 

現在沒有什麼會得到迴應...我試過var_dump(get_defined_vars());除了這些複選框之外,其他每個變量都被定義。甚至沒有在那裏顯示「空」。出了什麼問題?

+1

嘗試'var_dump($ _ POST);'並檢查是否可以在那裏找到'services'。 –

+0

爲什麼所有的輸入名爲「services []」 –

+1

''add this and try –

回答

0

重來,我有同一個文件的動作,但你可以改變行動值將是任何複選框,否則你不能得到CheckBox值

在您的形式沒有任何接近<form>標籤,而不是提交檢查後出現像按鈕的形式操作或submit button

<?php if(isset($_POST['services'])) 
{ 
    foreach($_POST['services'] as $services) 
    { 
     echo $services; 
    } 
}?> 

<html> 
<body> 
<form enctype="multipart/form-data" action="" method="post" class="wpcf7-form"> 
<div class="form-row"><span class="label--input-group">Services you require</span><span class="wpcf7-form-control-wrap services"><span class="wpcf7-form-control wpcf7-checkbox check-group-input"><span class="wpcf7-list-item"> 
      <label> 
      <input type="checkbox" name="services[]" value="Branding" /> 
      &nbsp;<span class="wpcf7-list-item-label">Branding</span></label> 
      </span><span class="wpcf7-list-item"> 
      <label> 
      <input type="checkbox" name="services[]" value="Design" /> 
      &nbsp;<span class="wpcf7-list-item-label">Design</span></label> 
      </span><span class="wpcf7-list-item"> 
      <label> 
      <input type="checkbox" name="services[]" value="Other" /> 
      &nbsp;<span class="wpcf7-list-item-label">Other</span></label> 
      </span><span class="wpcf7-list-item"> 
      <label> 
      <input type="checkbox" name="services[]" value="Development" /> 
      &nbsp;<span class="wpcf7-list-item-label">Development</span></label> 
      </span><span class="wpcf7-list-item"> 
      <label> 
      <input type="checkbox" name="services[]" value="Illustration" /> 
      &nbsp;<span class="wpcf7-list-item-label">Illustration</span></label> 
      </span></span></span></div> 
      <input type="submit" name="sub"> 
      </form> 
</body> 
</html> 
1

你已經錯過了關閉<form>標籤,並添加提交按鈕

<input type="submit" name="submit" value="submit"> 
    </form> 
0


實際上您並未提交表單。你剛剛在'行動'中指定。要實現您的代碼可行,請添加一個提交按鈕。所以,點擊它會調用processstart.php

<input type="submit">