2017-08-08 120 views
0

試圖通過Post在我的PHP中檢查哪個單選按鈕被選中,但出於某種原因,我沒有任何價值。其他人是否看到我要去哪裏?表單經過驗證後通過javascript提交。如果需要,我可以提供該代碼。爲單選按鈕獲取空白值

按鈕組HTML:

<!-- Start Purchase Radio --> 
    <div class="form-group"> 
     <div class="radio"> 
      <label> 
       <input type="radio" name="transType" id="transTypePurchase" value="purchase"> 
       Purchase 
      </label> 
     </div> 
    </div> 
<!-- End Purchase Radio --> 

<!-- Start Refinance Radio --> 
    <div class="form-group"> 
     <div class="radio"> 
      <label> 
       <input type="radio" name="transType" id="transTypeRefinance" value="refinance"> 
       Refinance 
      </label> 
     </div> 
    </div> 
<!-- End Refinance Radio --> 

<!-- Start Transfer Radio --> 
    <div class="form-group"> 
     <div class="radio"> 
      <label> 
       <input type="radio" name="transType" id="transTypeTransfer" value="transfer"> 
       Transfer 
      </label> 
     </div> 
    </div> 
<!-- End Transfer Radio --> 

<!-- Start Other Radio --> 
    <div class="form-group"> 
     <div class="input-group"> 
      <span class="input-group-addon"> 
       <input type="radio" aria-label="Radio button for following text input" name="transType" id="transTypeOther"> 
      </span> 
      <input type="text" class="form-control" aria-label="Text input with radio button" name="transType" id="transcationOtherText" onfocus="otherTextBox(transcationOtherText);" placeholder="Other"> 
     </div> 
    </div> 
<!-- End Other Radio --> 

PHP:

if(isset($_POST['transType'])) { 
    $value = $_POST['transType']; 
    echo "*" . $value . "*"; 
} 
+0

你的同名文字輸入內容是什麼?我相信它總是會使用輸入框的內容,因爲它是頁面上最後一個使用該名稱的元素 – GrumpyCrouton

+1

'print_r($ _ POST);'是否包含其他預期的鍵/值? – Rasclatt

+0

感謝您的快速響應!答案如下。這是我的「其他」文本字段的名稱與收音機相同。一旦我改變了它,我就獲得了無線電價值。 –

回答

2

你有相同的名稱作爲文本輸入的無線輸入。請參閱

<input type="text" class="form-control" aria-label="Text input with radio button" name="transType" id="transcationOtherText" onfocus="otherTextBox(transcationOtherText);" placeholder="Other"> 

更改上述輸入的名稱。

+0

就是這樣......花了2個小時試圖弄清楚。定時器啓動時,將其標記爲正確的答案。謝謝。 –