[英]html form autofill with php
i have two forms , in the first form i am taking an user input with post action and i will run a SELECT query with a WHERE clause, i am using php in the backend. 我有两种形式,在第一种形式中,我将通过后期操作接受用户输入,并且我将使用WHERE子句运行SELECT查询,我在后端中使用php。 I am storing the retrieved value in a session variable to make it global.
我将检索到的值存储在会话变量中以使其全局。 i will be displaying the session variable in my second form.
我将以第二种形式显示会话变量。 The problem is that it shows the old form value in the session variable.
问题在于它在会话变量中显示了旧的表单值。 is there a way i can load the 2nd form only after i finish the post operation?
我只有在完成后期操作后才能加载第二种表格吗? code for form1 below
下面的form1的代码
<form action="autofillStudent.php" method="post" enctype="multipart/form-data" target="update_target" >
<div class="form-group">
<label for="formGroupExampleInput10">USN</label>
<input type="text" class="form-control" id="formGroupExampleInput10" placeholder="USN" required = " true" name = "qusn">
</div>
<button type="submit" id="toggleform2" class="btn btn-default" name = "Update" required = "true" value="login" >Update student Details</button>
<iframe id="update_target" name="update_target" src="#" style="width:0;height:0;border:0px solid #fff;"></iframe>
</form>
i am posting qusn and storing the database result in $_SESSION['usn'] 我正在发布qusn并将数据库结果存储在$ _SESSION ['usn']中
code for form2 below 下面的form2的代码
<form action="updateStudent.php" method="post" enctype="multipart/form-data">
<label for="formGroupExampleInput2">Name</label>
<input type="text" class="form-control" id="formGroupExampleInput2" placeholder="Name" required = " true" name = "sname" value = <?php echo $_SESSION['usn'];?> >
</form>
Here i have echoed $_SESSION['usn'] , since the form gets loaded before itself, it displays the old value. 在这里,我已经回显了$ _SESSION ['usn'],因为表单在其自身之前被加载,因此显示旧值。 I want to know a way to call the 2nd form like a function , or just reload that part only.
我想知道一种像函数一样调用第二种形式的方法,或者只重装该部分。 I dont want to refresh the entire page.
我不想刷新整个页面。
Did you try putting the second code snippet in a different file and after the first form has been submitted load the second one with an ajax request? 您是否尝试过将第二个代码片段放入另一个文件中,并且在提交第一个表单之后,用ajax请求加载第二个代码片段?
OR 要么
You can just use: 您可以使用:
$("#form-1").ajaxForm({
/*...*/,
complete: function() {
$("#form-2").css('display', 'block');
$("#formGroupExampleInput2").val(firstValue);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.