Forms 在Phalcon框架中清除表单中填写的数据

Forms 在Phalcon框架中清除表单中填写的数据,forms,frameworks,phalcon,Forms,Frameworks,Phalcon,我是phalcon的新手,正在尝试学习这个框架。我创建了一个简单的表单。现在,当我填写表单时,我能够将数据存储在数据库中。提交表格后,我希望在同一页上。现在的问题是,表单仍然有未清理的已填充数据。我在谷歌上搜索并找到了清除表单数据的clear()方法,但它似乎不起作用。怎么办 这是我的密码 //控制器 use Phalcon\Mvc\Controller; class ProfileController extends Controller { public function index

我是phalcon的新手,正在尝试学习这个框架。我创建了一个简单的表单。现在,当我填写表单时,我能够将数据存储在数据库中。提交表格后,我希望在同一页上。现在的问题是,表单仍然有未清理的已填充数据。我在谷歌上搜索并找到了清除表单数据的clear()方法,但它似乎不起作用。怎么办

这是我的密码 //控制器

use Phalcon\Mvc\Controller;
class ProfileController extends Controller
{
    public function indexAction()
    {

        // Add some local CSS resources
        $this->assets->addCss("css/styles.css");
        $this->assets->addCss("css/bootstrap.min.css");

        // And some local JavaScript resources
        $this->assets->addJs("js/jquery.js");
        $this->assets->addJs("js/bootstrap.min.js");

    }

    public function createAction(){

        //create object of model class
        $profile = new Tbl_profile();

        $profile->fname= $this->request->getPost('firstname');
        $profile->lname= $this->request->getPost('lastname');
        $profile->email= $this->request->getPost('email');
        $success=$profile->save();

        if($success) {
            $this->flash->success("Profile created!");
            //redirect to same page.

            $this->dispatcher->forward(['action' => 'index']);
        }else {

        }


    }
}
//观点

<html>
<head>
    <title>Title</title>
    <?php $this->assets->outputCss(); ?>
</head>
<body>
        <h4 class="ml-5 mt-2"> Create Profile</h4>
        <?php echo $this->getContent(); ?>
        <?php echo $this->tag->form("profile/create") ?>
        <table class="table">
            <tbody>
                <tr scope="row">
                    <td>First Name</td>
                    <td><?php echo $this->tag->textField("firstname"); ?></td>
                </tr>
                <tr scope="row">
                    <td>Last Name</td>
                    <td><?php echo $this->tag->textField("lastname"); ?></td>
                </tr>
                <tr scope="row">
                    <td>Email</td>
                    <td><?php echo $this->tag->textField("email"); ?></td>
                </tr>
                <tr scope="row">
                    <td></td>
                    <td><?php echo  $this->tag->submitButton("Create");?></td>
                </tr>
            </tbody>

        </table>
</form>
</body>
</html>

标题
创建配置文件
名字
姓
电子邮件

将数据保存到数据库后,请重定向到控制器,而不是转发请求,因为转发请求不会重新加载页面

$this->request->redirect('profile/index');

阅读本文了解更多信息

您必须创建表单类,才能使用
$form->clear()
方法

见医生