我是php
的初学者,在按下提交按钮并告诉您输入值后,我想做一些隐藏的表单,但它不起作用。我认为我的提交按钮存在一些问题(我花了2个小时试图解决这个问题)。感谢
<!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 :(得分:0)
我认为那是因为您没有设置提交输入的名称,但是您正在验证PHP中的输入是否为isset:
将您的代码更改为。
<input type="submit" value="submit" name="submit">
答案 1 :(得分: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>");
?>