gpt4 book ai didi

php - 发生错误后不要清除文本框值

转载 作者:可可西里 更新时间:2023-10-31 22:42:50 25 4
gpt4 key购买 nike

我希望在发送数据后,如果发生错误,它不会删除已经写入文本框或复选框的数据。我怎样才能做到这一点?这是 html 代码:

<form action="adaugare-elev.php?actiune=validare" method="post">
Date de contact <br>
<table>
<tr><td>Nume: <th><input type="text" name="nume" required></th></td></tr>
<tr><td>Prenume: <th><input type="text" name="prenume" required></th></td></tr>
<tr><td>Seria: <input type="text" style="width:25px;" name="seria" required></td> <td>Nr: <input type="text" name="nr" style="width:50px;" name="nr" required></td></tr>
<tr><td>CNP: <th><input type="text" name="cnp" required></th></td></tr>
<tr><td>Mail: <th><input type="text" name="mail" required></th></td></tr>
<tr><td>Loc de munca: <th><input type="text" name="locmunca" required></th></td></tr>
</table><br>
</form>

这是表单的 php 代码:

if(!isset($_GET['actiune'])) 
$_GET['actiune'] = '';
switch($_GET['actiune'])
{
case 'validare':
$_SESSION['nume'] = $_POST['nume'];
$_SESSION['prenume'] = $_POST['prenume'];
$_SESSION['seria'] = $_POST['seria'];
$_SESSION['nr'] = $_POST['nr'];
$_SESSION['cnp'] = $_POST['cnp'];
$_SESSION['mail'] = $_POST['mail'];
$_SESSION['locmunca'] = $_POST['locmunca'];
$inserare = "insert into `elevi` (`nume`,`prenume`,`nr`,`cnp`,`mail`,`locmunca`,) values ('".addentities($_SESSION['nume'])."','".addentities($_SESSION['prenume'])."','".addentities($_SESSION['nr'])."','".addentities($_SESSION['cnp'])."','".addentities($_SESSION['mail'])."','".addentities($_SESSION['locmunca'])."')";
}

我尝试使用弹出窗口 alert (echo "<script>alert('Something's wrong')</script>";在 if 子句之后)但它没有用..

最佳答案

您需要检查,是否设置了发布数据,如果是,则将其设置为输入值。例如:

<tr><td>Nume: <th><input type="text" name="nume" value="<?php if (!empty($_POST["nume"])) { echo $_POST["nume"]; } else { echo ''; };  ?>" required></th></td></tr>

关于php - 发生错误后不要清除文本框值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27546344/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com