2017-09-25 47 views
0

我有一個模態表單。當我按下提交按鈕的PHP文件運行時出現以下錯誤: 注意:未定義的索引:phone1在C:\ xampp \ htdocs \ site \ bank.php在線2 注意:未定義的索引:charge1 in C:\ xampp在第4行將模態表單值發佈到PHP文件

這裏\ htdocs中\站點\ bank.php是在bank.php PHP代碼:

<?php 
 
echo $_POST["phone"]; 
 
echo "</br>"; 
 
echo $_POST["charge"]; 
 
?>

這裏是模態內容:

<!-- Modal content--> 
 

 
<div class="modal fade" id="register" role="dialog"> 
 
    <div class="modal-dialog"> 
 
    <div class="modal-content"> 
 
     <div class="modal-header"> 
 
     <button type="button" class="close" data-dismiss="modal">&times;</button> 
 
     <h4 class="modal-title">Modal title here</h4> 
 
     </div> 
 
     <div class="modal-body"> 
 
     <form id="modal-form" class="form-horizontal" method="POST" action="bank.php"> 
 
      <div class="form-group col-md-12"> 
 
      <div class="form-group"> 
 
       <div class="col-xs-6" style="float:right;"> 
 
       <label>phone numer:</label> 
 
       <input id="phone" type="text" class="form-control" name="phone" value="pre filled value" disabled/> 
 
       <span id='display'></span> 
 
       </div> 
 
       <div class="col-xs-6" style="float:left;"> 
 
       <label>charge:</label> 
 
       <input style="font-size:17px; font-weight:bold;" id="charge" type="text" class="form-control" name="charge" value="some other prefilled value" disabled/> 
 
       </div> 
 
      </div> 
 
      </div> 
 
      <div class="form-group"> 
 
      <div class="col-xs-12"> 
 
       <button class="btn btn-danger btn-default pull-right" data- dismiss="modal" style="margin-left:10px;">close</button> 
 
       <button type="submit" class="btn btn-success"> submit </button> 
 
      </div> 
 
      </div> 
 
     </form> 
 
     </div> 
 
     <div class="modal-footer"> 
 
     modal footer 
 
     </div> 
 
    </div> 
 

 
    </div> 
 
</div>

如果有一個人幫我找出我將感謝的東西;不對本

+1

你的表單有'phone1',你的回聲是'$ _POST [「phone」]'哪一個是正確的? – teeyo

+1

以及名稱是電話1不是電話....和charge1不收費....名稱被髮送,而不是ID .... – epascarello

+1

您正在命名您的參數與數字(phone1,charge1),但你的php代碼回聲沒有數字('$ _POST ['change']') – gmc

回答

0

不相關,OP編輯他的問題。 參見相關答案編輯

帖子變量的名稱由輸入的name屬性定義,而不是id。 因此在你的bank.php你將有$_POST['phone1']$_POST['charge1']可用。 你總是可以只用var_dump($_POST);來查看所有可用的變量。

編輯:此外,被禁用的輸入不會在提交時發送。您可以解決這一事實只需添加第二個隱藏輸入每個禁用一個這樣的:

<!-- Modal content--> 

<div class="modal fade" id="register" role="dialog"> 
    <div class="modal-dialog"> 
    <div class="modal-content"> 
     <div class="modal-header"> 
     <button type="button" class="close" data-dismiss="modal">&times;</button> 
     <h4 class="modal-title">Modal title here</h4> 
     </div> 
     <div class="modal-body"> 
     <form id="modal-form" class="form-horizontal" method="POST" action="bank.php"> 
      <div class="form-group col-md-12"> 
      <div class="form-group"> 
       <div class="col-xs-6" style="float:right;"> 
       <label>phone numer:</label> 
       <input id="phoneDisabled" type="text" class="form-control" name="phoneDisabled" value="pre filled value" disabled/> 
       <input id="phone" type="hidden" class="form-control" name="phone" value="pre filled value" disabled/> 
       <span id='display'></span> 
       </div> 
       <div class="col-xs-6" style="float:left;"> 
       <label>charge:</label> 
       <input style="font-size:17px; font-weight:bold;" id="chargeDisabled" type="text" class="form-control" name="chargeDisabled" value="some other prefilled value" disabled/> 
       <input style="font-size:17px; font-weight:bold;" id="charge" type="hidden" class="form-control" name="charge" value="some other prefilled value" disabled/> 
       </div> 
      </div> 
      </div> 
      <div class="form-group"> 
      <div class="col-xs-12"> 
       <button class="btn btn-danger btn-default pull-right" data- dismiss="modal" style="margin-left:10px;">close</button> 
       <button type="submit" class="btn btn-success"> submit </button> 
      </div> 
      </div> 
     </form> 
     </div> 
     <div class="modal-footer"> 
     modal footer 
     </div> 
    </div> 

    </div> 
</div> 

EDIT2:或者,只是改變disabled屬性readonly

+0

我已經改變了name1名稱,但仍然是同樣的問題,這裏是var_dump($ _ POST)結果︰array(0){} –

+0

編輯我的答案,看看 – Cashbee

+0

哇,這是偉大的感謝,禁用字段是重點,非常感謝 –

0

的名稱與$_POST變量和HTML input名稱都不同。請儘量讓它們相同,希望你的代碼能夠正常工作。

name=phone1更改爲name=phone或其他。

+0

我修改了代碼,但仍然是相同的錯誤 –

0

您設置了這些投入如已禁用。表單默認不會發布這些。您可能需要使用JavaScript獲取變量,或者使用JavaScript再次刪除禁用的屬性。