drxyaox153896 2018-06-10 07:03
浏览 324

用PHP填写html表单自动填充

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. 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

    <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']

code for form2 below

    <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. 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.

  • 写回答

1条回答 默认 最新

  • duanph1978 2018-06-10 07:32
    关注

    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?

    OR

    You can just use:

    $("#form-1").ajaxForm({
        /*...*/,
        complete: function() {
            $("#form-2").css('display', 'block');
            $("#formGroupExampleInput2").val(firstValue);
        }
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab