简体   繁体   English

如何发送表格但与phalcon保持同一页面?

[英]How do I send a form but stay on the same page with phalcon?

In the form I have to define a handler like admin/login . 在表单中,我必须定义一个类似于admin/login的处理程序。 Then it changes the page when I send it. 然后,当我发送页面时,它会更改页面。 I also tried using public function indexAction() handler and only using the controller admin without a handler, but then nothing happens. 我还尝试使用public function indexAction()处理程序,并且仅使用不带处理程序的控制器admin ,但是随后什么也没有发生。

Any help would be greatly appreciated. 任何帮助将不胜感激。

Edit: 编辑:
I wanted to have a error message but it was not so big a site that i wanted to make a form class. 我想收到一条错误消息,但它不是一个很大的站点,所以我想制作一个表单类。

The way i eventually fixed it was the following: 我最终修复它的方式如下:

First i use $this->view->pick('admin/index'); 首先我使用$this->view->pick('admin/index'); in the handler to select my old view. 在处理程序中选择我的旧视图。
Next i send a variable like a error message with $this->view->setVars(['username' => $user->name,]); 接下来,我使用$this->view->setVars(['username' => $user->name,]);发送类似错误消息的变量$this->view->setVars(['username' => $user->name,]); in the handler. 在处理程序中。
Last i used it with volt in the previous view views/admin/index.phtml like this {{ username }} 最后,我在上一个视图views/admin/index.phtml中将它与volt一起使用,像这样{{ username }}

If you are using a form object you can then use the following code in your volt template 如果您使用的是表单对象,则可以在volt模板中使用以下代码

{{ form('myform', 'method':'post', 'role': 'form') }}

This will post your data to the same controller/action that invoked the form. 这会将您的数据发布到调用该表单的相同控制器/操作中。 From then you will be able to handle the posted data using valid() in the form as well as request->isPost() 从那时起,您将能够使用表单中的valid()以及request->isPost()处理已发布的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM