2016-11-08 61 views
0

當通過$ _POST提交表單時,輸入文件值將保留。就像這樣:textarea和選擇輸入的數據或值保留

if($_POST){ 
    $error = false; 
      if(!$post['price']){  
       $error = true; 
       $error_note['price'] = "*Should not be empty"; 
      }  
    if($error == false){ 
    //submit/save the data 
    } 
} 



<form name="post" id="post" method="post" action=""> 
      <input name="price" value="<?=$_POST['price']?>" class="text-input" type="text" maxlength="15"> 
      <select name="price-type" class="text-input"> 
           <option value="" selected>Select price type</option> 
           <option value="item">Item</option> 
           <option value="kilo">Kilo</option> 
           <option value="rate">Rate</option> 
      </select> 

      <textarea class="description" name="description" cols="55%" rows="6"></textarea> 

     <button class="button" type="submit" name="submit-btn" >SUBMIT</button> 
    </form> 

但我有textarea的和我的表格上選擇輸入。

如何在選擇輸入中保留textarea和選定項目的內容? value="<?=$_POST['price']?>"不會把這種工作..

+0

做出價值=「isset($ _ POST [ '價格'])? $ _POST ['price']:''「 –

+1

+0

檢查textarea的第二條評論。 –

回答

1

檢查這一點,可以幫助你

<form name="post" id="post" method="post" action=""> 
    <input name="price" value="<?=isset($_POST['price']) ? $_POST['price'] : ''?>" class="text-input" type="text" maxlength="15"> 
    <select name="price-type" class="text-input"> 
     <option <?= (isset($_POST['price-type']) && $_POST['price-type']=='') ? 'selected' : '' ?> value="" >Select price type</option> 
     <option <?= (isset($_POST['price-type']) && $_POST['price-type']=='item') ? 'selected' : '' ?> value="item">Item</option> 
     <option <?= (isset($_POST['price-type']) && $_POST['price-type']=='kilo') ? 'selected' : '' ?> value="kilo">Kilo</option> 
     <option <?= (isset($_POST['price-type']) && $_POST['price-type']=='rate') ? 'selected' : '' ?> value="rate">Rate</option> 
    </select> 
    <textarea class="description" name="description" cols="55%" rows="6"><?=isset($_POST['description']) ? $_POST['description'] : '' ?></textarea> 
    <button class="button" type="submit" name="submit-btn" >SUBMIT</button> 
</form> 
+0

對你來說很簡單!我只是編輯一些你的代碼來滿足我的需求。非常感謝! –

+0

當我使用jQuery生成選擇項時,是否可以使用它? –

+0

你可以顯示一些代碼,所以我可以幫助y OU。 –

0

您已經使用short tag但請注意,你的短標籤也應打開此

我建議總是使用PHP的標籤

value="<?php echo $_POST['price']; ?>" 

制定短期打開標籤

short_open_tag=On //in php.ini 

restart您的Apache server.

+0

我的短標籤在輸入文本類型上運行良好,但不能在textarea上工作並選擇輸入,這是我的問題,而不是'short tag' –

+0

這不是short_open_tag –