2014-12-03 62 views
0

我在每行中都有一個名爲「edit」的提交按鈕顯示文本列表。在php中未經檢查的值的Post方法

我正在使用post方法。

當用戶想要編輯多個文本時,他們可以選中一個複選框,他們可以點擊任何「編輯」按鈕。而且我知道當用戶選中複選框時如何處理文本。

但是,如果他們只想編輯一個文本,那麼它不需要檢查複選框。

如何處理如果用戶沒有檢查任何複選框。

例如,用戶想要編輯房間,他點擊同一行中的「編輯」按鈕。 我如何在post方法中獲得此文本。 所有這些文本是動態的我是從數據base.row

<form method='post' action="edit.php"> 
<tr><td> 
<input type="checkbox" value="1" name="check_list[]"> 
</td><td><input type='text' name="text[]" value="casa|house|home" /></td> 
    <td><input type="submit" value="edit></td> 
    </tr> 
< tr><td> 
<input type="checkbox" value="2" name="check_list[]"> 
</td><td><input type='text' name="text[]" value="apartments" /></td> 
    <td><input type="submit" value="edit></td> 
    </tr> 

回答

1

越來越如果設置了提交按鈕的名稱,你會得到他們項下的$ _POST陣列英寸然後,您可以過濾$ _POST以查找按下哪個按鈕。

---在HTML ---

<input type="submit" name="edit_1" value="edit> 

---在action.php的---

foreach($_POST as $key => $value) {  // run over list of posted fields 
    if(strpos($key, "edit_") === 0) {  // if it starts with edit_ 
    $valueOfPressedButton = substr($key, 5); // strip away the edit_ so that only the number of the button remains 
    } 
} 

請記住,是處理輸入一個相當奇怪的方式和意志作爲結果,不要在代碼中直截了當。

+0

你能告訴我如何處理「edit.php」(我的意思是在動作url頁面) – user3560322 2014-12-03 11:07:42

+0

恢復這樣的關鍵作品。剩下的你必須自己做。 – Erik 2014-12-03 11:11:56

+0

Thanq其工作正常:-) – user3560322 2014-12-03 11:22:19