2016-04-30 61 views
0

我是php的初學者,我想在按下提交按鈕之後做一些隱藏的表單,並告訴你輸入值,但它不起作用。我認爲我的提交按鈕存在一些問題(我花了2個小時試圖解決這個問題)。由於PHP我的表單不會提交

<!DOCTYPE HTML> 
<html> 
<head> 
<title>Jednoduchý formulář</title> 
</head> 
<body> 
    <?php 
    $show = True; 
    if(isset($_GET['submit'])){ 
    if(empty($_GET['jmeno'])){echo "Vyplnte jmeno";}else { 
     if (empty($_GET['prijmeni'])){echo "Vyplnte prijmeni";}else{ 

    echo "Jméno: ".$_GET['jmeno']; 
     echo "<br>"; 
    echo "Prijmeni: ".$_GET['prijmeni']; 
     echo "<br>"; 
    echo "Je Vám ".$_GET['vek']; 
     echo "<br>"; 
    echo "Děkuji za vyplnění formuláře"; 

    $show=False; 
    }; 
    }; 
}; 

    if ($show){ ?> 
<form action="form1.php" method="get" > 
<table width="250" align="center"> 
    <tr> 
    <td>Jmeno:</td> <td><input type="text" name="jmeno" value="" size="10" maxlength="25"></td> 
    </tr> 

    <tr> 
    <td>Prijmeni:</td> <td><input type="text" name="prijmeni" value="" size="10" maxlength="25"></td> 
    </tr> 

    <tr> 
    <td>Heslo:</td> <td><input type="password" name="heslo" value="" size="10" maxlength="15"></td> 
    </tr> 

    <tr> 
    <td>Vek</td> <td><input type="radio" name="vek" value="méně než 18 let "checked> mene nez 18 <br> 
        <input type="radio" name="vek" value="18 let a více"> 18 a vice </td> 
    </tr> 
    <tr> 
    <td></td><td><input type="submit" value="submit"></td> 
    </tr> 
</table> 
</form> 

<?php 
    }; 
    ?> 
</body> 
</html> 

回答

0

我想那是因爲你還沒有設置提交輸入的名字,但你verifiying在PHP該輸入被isset:

更改你的代碼。

<input type="submit" value="submit" name="submit"> 
+0

哇,非常感謝你的工作。那個小小的錯誤讓你感到非常麻煩,你在幾秒鐘之內就解決了它。非常感謝。 – ochj1ch

+0

沒關係。如果解決了您的問題,請將答案標記爲正確。在將來嘗試逐一驗證php的每一行,你會很容易地發現錯誤。 –

0

您應該使用$_POST(),除此之外,您需要命名提交的輸入,然後檢查它的設置。

<?php 

IF (isset($_POST['form1'])) { 

    $err = ""; 
    IF (!empty($_POST['jmeno'])) { $jmeno = $_POST'jmeno']; }ELSE{ $err .= "jmeno is empty.<br>"; } 
    IF (!empty($_POST['prijmeni'])) { $prijmeni = $_POST'prijmeni']; }ELSE{ $err .= "prijmeni is empty"; } 
    IF (!empty($_POST['heslo'])) { $heslo = $_POST'heslo']; }ELSE{ $err .= "heslo is empty"; } 
    // ...... etc. 

    IF (!empty($err)) { 

     $result = "<p>".$err."</p>"; 
     $result .= "<form action=\"form1.php\" name=\"form1\" method=\"post\" > 
<table width=\"250\" align=\"center\"> 

    <tr> 
    <td>Jmeno:</td> <td><input type=\"text\" name=\"jmeno\" value=\"".$_POST['jmeno']."\" size=\"10\" maxlength=\"25\"></td> 
    </tr> 

    <tr> 
    <td>Prijmeni:</td> <td><input type=\"text\" name=\"prijmeni\" value=\"".$_POST['prijmeni']."\" size=\"10\" maxlength=\"25\"></td> 
    </tr> 

    <tr> 
    <td>Heslo:</td> <td><input type=\"password\" name=\"heslo\" value=\"".$_POST['heslo']."\" size=\"10\" maxlength=\"15\"></td> 
    </tr> 

    <tr> 
    <td>Vek</td> <td><input type=\"radio\" name=\"vek\" value=\"méne než 18 let \"checked> mene nez 18 <br> 
        <input type=\"radio\" name=\"vek\" value=\"18 let a více\"> 18 a vice </td> 
    </tr> 
    <tr> 
    <td></td><td><input type=\"submit\" name=\"form1\" value=\"submit\"></td> 
    </tr> 
</table> 
</form>"; 

    }ELSE{ 

     // everything is good to go.... 
     $result = "whatever the next html body should be."; 

    } 

}ELSE{ 

    $result = "<form action=\"form1.php\" name=\"form1\" method=\"post\" > 
<table width=\"250\" align=\"center\"> 

    <tr> 
    <td>Jmeno:</td> <td><input type=\"text\" name=\"jmeno\" value=\"\" size=\"10\" maxlength=\"25\"></td> 
    </tr> 

    <tr> 
    <td>Prijmeni:</td> <td><input type=\"text\" name=\"prijmeni\" value=\"\" size=\"10\" maxlength=\"25\"></td> 
    </tr> 

    <tr> 
    <td>Heslo:</td> <td><input type=\"password\" name=\"heslo\" value=\"\" size=\"10\" maxlength=\"15\"></td> 
    </tr> 

    <tr> 
    <td>Vek</td> <td><input type=\"radio\" name=\"vek\" value=\"méne než 18 let \" checked> mene nez 18 <br> 
        <input type=\"radio\" name=\"vek\" value=\"18 let a více\"> 18 a vice </td> 
    </tr> 
    <tr> 
    <td></td><td><input type=\"submit\" name=\"form1\" value=\"submit\"></td> 
    </tr> 
</table> 
</form>"; 

} 

// display results 
echo("<!DOCTYPE HTML> 
<html> 
<head> 
<title>Jednoduchý formulár</title> 
</head> 
<body> 
".$result." 
</body> 
</html>"); 

?>