【问题标题】:how to refill data after reloading page in php如何在php中重新加载页面后重新填充数据
【发布时间】:2017-12-23 10:17:32
【问题描述】:

我被困在一个点上。我有一个 php 表单,填写完所有详细信息后,用户必须按下提交按钮。如果数据没有正确提交,那么我正在重新加载页面。

所以我的问题是。

我想将用户以前输入的所有值设置为受尊重 没有请求方法的字段。

我怎样才能做到这一点?

到目前为止我做了什么

我的user.php

<?php
$name = '';

if(isset($_REQUEST[name]))
{
   $name = $_REQUEST[name]; 
}

if(isset($_POST["submit"]))
{
   $name = $_POST["txtname"];

  header('Location:user.php?name=<?php echo $name; ?>');

}

?>

<hrml>
<body>
<form name="form1" id="form1" method="POST">
<label>Name:</label>
<input type="text" name="txtname" id="txtname" value="<?php echo $name; ?>">
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>

编辑

apply_now.php

    <?php 
    $CLASS__BL = 'apply_now_bl';
    require_once('apply_now_bl.php');

    ?>

    <form name="form1" id="form1" action="" method="post" enctype="multipart/form-data">


                    <div class="form-group">
                      <label for="input-label">Full Name: *</label>
                      <input name="txtname" id="txtname" type="text" class="form-control" value="<?= @$page_bl->full_name; ?>">
                    </div>
</form>

apply_now_bl.php

<?php 
require_once('admin/db_lib/candidates.php');
require_once('includes/general_include.php');

$page_bl = apply_now_bl();
page_load();

class apply_now_bl
{

    var $full_name = '';

function page_load()
    {
        $this->obj_candidates = new candidates();

        if(isset($_POST["submit"]))
        {
            $this->submit_data();
        }

    }

    function submit_data()
    {
        $this->full_name = get_post_val("txtname"); 
        $this->obj_candidates->full_name =  $this->full_name;

        redirect(apply_now.php); //common function for page redirect
    }
}

【问题讨论】:

  • 你到底想要什么
  • 我想在没有请求方法的情况下取回发布的数据。
  • 表示这是一种个人资料表单,您想在保存到数据库后获取数据,对吗?
  • 不,亲爱的 Soubhagya Kumar,当我提交表单数据并进入 php 端然后通过服务器验证拒绝数据然后返回页面并显示消息时(例如,请选择有效的文件类型)。正确填写输入的数据。
  • 哦,知道了,给我 5 分钟

标签: php forms http-post


【解决方案1】:

无需通过 php 标头位置重定向。因为 action 是空白的,这意味着一旦表单提交它将重定向到 user.php(current page)。

所以下面是更新的代码

<?php
$name = "";
if (isset($_POST["submit"])) {
    $name = $_POST["txtname"];
}
?>
<html>
    <body>
        <form name="form1" id="form1" method="POST">
            <label>Name:</label>
            <input type="text" name="txtname" id="txtname" value="<?php echo $name; ?>">
            <input type="submit" name="submit" value="submit">
        </form>
    </body>
</html>

【讨论】:

  • No i need of redirect page Like&lt;?php $name = ""; if (isset($_POST["submit"])) { $name = $_POST["txtname"]; header('location:file.php'); } ?&gt;
猜你喜欢
  • 1970-01-01
  • 2017-07-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-05
  • 1970-01-01
相关资源
最近更新 更多