清除Phalcon Framework中填写的表单数据

时间:2018-05-29 14:41:44

标签: forms frameworks phalcon clear

我是phalcon的新手,并试图学习这个框架。我创建了一个简单的表单。现在,当我填写表单时,我能够将数据存储在数据库中。提交表单后,我想要在同一页面上。现在的问题是,表格仍然没有清理填充的数据。我用Google搜索并找到了 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 {

        }


    }
}

// views

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

2 个答案:

答案 0 :(得分:0)

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

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

阅读此Order.cs以获得更多信息

答案 1 :(得分:0)

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

请参阅文档https://docs.phalconphp.com/cs/3.4/forms