Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP使用File_get_Contents()预填充表单_Php_Jquery - Fatal编程技术网

PHP使用File_get_Contents()预填充表单

PHP使用File_get_Contents()预填充表单,php,jquery,Php,Jquery,我在一个网站上工作,帮助学习一些PHP MVC。目前,该网站执行的凝乳命令,但我期待着改善他们 数据库项显示在on列中,有两个按钮,一个用于删除,一个用于更新。当用户单击更新按钮时,将显示一个表单(update\u item\u form.php),允许用户输入要更新的项目信息。表单由三个字段组成(标题、价格和说明) 我试图做的是:当用户单击更新按钮时,表单将预先填充与该行相关的所有项目信息 当用户单击按钮时,如何将行信息发送到表单 文件获取内容() Update\u item\u form.p

我在一个网站上工作,帮助学习一些PHP MVC。目前,该网站执行的凝乳命令,但我期待着改善他们

数据库项显示在on列中,有两个按钮,一个用于删除,一个用于更新。当用户单击更新按钮时,将显示一个表单(
update\u item\u form.php
),允许用户输入要更新的项目信息。表单由三个字段组成(标题、价格和说明)

我试图做的是:当用户单击更新按钮时,表单将预先填充与该行相关的所有项目信息

当用户单击按钮时,如何将行信息发送到表单

文件获取内容()

Update\u item\u form.php

<h2>Update Item!</h2>
<h4>Fill in the form to update an entry.</h4>
<form action="index.php" method="post">
<fieldset>
    <input id='action' type='hidden' name='action' value='updateItem' />
    <p>
        <label for="fTitle">Title</label> <input type="text"
            id="fTitle" name="fTitle" placeholder="title"
            maxlength="25" required />
    </p>
    <p>
        <label for="fPrice">Price</label> <input type="text"
            id="fPrice" name="fPrice" placeholder="price"
            maxlength="25" required />
    </p>
    <p>
        <label for="fDescription">Description</label> <input type="text"
            id="fDescription" name="fDescription" placeholder="description"
            maxlength="500" required />
    </p>

    <p>
    <div class="form-group">
        <div class="controls">
            <button type="submit" class="btn btn-success">Submit</button>
        </div>
    </div>
    </p>
</fieldset>
更新项目!
填写表格以更新条目。

标题

价格

描述

提交


file\u get\u内容不会解析PHP文件。您所做的只是将代码加载到
$rightBox
中,而不是我假设您要的输出

为此,可以使用输出缓冲

ob_start();
include "templates/update_item_form.php";
$rightBox = ob_get_clean();

这将在
ob_start()
ob_get_clean()
之间将输出存储到
$rightBox

CURD?小莫菲小姐会非常激动的。您必须能够解析返回的内容,以获得设置表单值所需的位。如果内容是标记,您可能需要类似DOMDocument的东西来执行解析。我提供了一个关于输出缓冲的答案,但您的问题有点到处都是,所以我不太确定您在问什么。好的,我要问的问题是,如果您没有任何php代码并且正在使用file\u get\u内容,那么update\u item\u form.php作为php文件的目的是什么?您的代码(控制器)应该将变量传递给模板(视图),模板应该显示它们。这只是转录中的一个错误over@patrick因为你似乎还没有弄明白这一点,我想我上面的评论会有所帮助,因为你说你使用的是MVC设计。在本例中,我假设
template/update\u item\u form.php
视图应该显示控制器传递给它的变量。您的模板文件中没有PHP,因此您不会使用该设计向最终用户显示任何变量。感谢您的回答,我在理解这一点上遇到了一些困难。但是,您能否解释一下我如何使用它来预填充表单?那么,什么是update\u item\u form.PHP?精简你的问题,让它更清楚,然后也许我可以提供更多的建议。更新的问题,使它更清楚一点
ob_start();
include "templates/update_item_form.php";
$rightBox = ob_get_clean();