2016-08-30 72 views
-2

我無法弄清楚,爲什麼這個非常簡單的使用從形式不工作的投入測試..

<?php 

echo "TEST"; 

echo "<pre>" . print_r($_POST, true) . "</pre>"; 

if(isset($_POST['SubmitButton'])){ //check if form was submitted 
    $input = $_POST['inputText']; //get input text 
    echo "Success! You entered: ".$input; 
} 
?> 

<html> 
<body> 
<form action="" method="post"> 
    <input type="text" name="inputText"/> 
    <input type="submit" name="SubmitButton"/> 
</form> 
</body> 
</html> 

當我展示它表明,它是空的數組。當我在輸入字段中輸入內容並單擊提交時,沒有任何更改。

The demo page

如果任何人有一個想法,謝謝,我將非常感激。

enter image description here

+0

是您在提交時重新載入頁面嗎? PHP代碼僅在頁面加載 –

+0

時執行,當您按下提交按鈕時會發生什麼? –

+0

頁面重新加載並且輸入字段被重置。但沒有任何內容存儲在數組 – Miron

回答

0

2東西

提交按鈕需要一個值= 「東西」,然後更改

echo "<pre>" . print_r($_POST, true) . "</pre>"; 

echo "<pre>" . print_r($_POST) . "</pre>"; 

如果需要,您只需要在 「真」將其作爲var返回,如

$blob = print_r($_POST, true); 
echo "<pre>" . $blob . "</pre>"; 
+1

*「SubmitButton需要一個值=」某事「」 - - 這是錯誤的。 –

+0

你真的認爲這是問題嗎?真? – developerwjk

+0

if(isset($ _ POST ['SubmitButton'])){isset應該做什麼沒有值?注:成功!你輸入了:「。$ input;不在圖片 –