简体   繁体   English

在第二页上无法识别表格发布

[英]Form post not being recognized on the 2nd page

I have a very very basic dilemma that i am struggling with @ the moment. 我有一个非常非常基本的困境,我正在努力@ @。 I have a Symfony form that posts to another page, essentially user is redirected to template_2 and the form exists on template_1. 我有一个发布到另一个页面的Symfony表单,本质上,用户被重定向到template_2,并且该表单存在于template_1上。 This I achieve like this: 我这样实现:

renderFormTag('module/template2');

In the action of template_2, I have the following code: 在template_2的操作中,我有以下代码:

if($request->isMethod('post'))
{
  // retrieve form values from the Form available in template 1 
   $params = $this->getRequestParameter('formFieldName');
   echo $params; 

}

However, this isn't happening. 但是,这没有发生。

Nothing is being echoed out. 什么都没有被呼应。 I put in an echo "hello" but that does not execute either. 我在回声“你好”,但也不执行。 Infact I put in an echo "hello" outside of the if condition and that does not echo either. 实际上,我在if条件之外放了一个回声“ hello”,它也不回声。

I doublechecked the name of the template and the action , and that part is good. 我仔细检查了模板和action的名称,那部分很好。

Can anybody tell me where I am messing up? 有人可以告诉我我在搞砸吗?

Check the generated HTML whether it is valid or not and then check if the url in form tag is present in the output of symfony app:routes your_application_name and if it's accept a POST request and you can check if the right route matched in the dev toolbar. 检查生成的HTML是否有效,然后检查symfony app:routes your_application_name的输出中是否存在form标记中的url symfony app:routes your_application_name ,是否接受POST请求,您可以检查dev工具栏中是否匹配了正确的路由。

If it's a symfony generated form, I think $this->getRequestParameter('formFieldName'); 如果是symfony生成的表单,我认为$this->getRequestParameter('formFieldName'); is wrong, because fields in generated form usually encapsulated into an array of the form name... so you should write $this->getRequestParameter('form_name[form_field_name]'); 这是错误的,因为生成表单中的字段通常封装在表单名称数组中...因此您应该编写$this->getRequestParameter('form_name[form_field_name]'); see the HTML or the base form class for the form name. 有关表单名称,请参见HTML或基本表单类。 But be aware if you accessing posted values this way (from the request) they'll never be validated , it would be batter to recreate the form, validate the submitted data and access them through the form, see an example here ( executeCreate and processForm methods in the action class). 但是请注意,如果您以这种方式(从请求中)访问发布的值将永远不会被验证 ,那么重新创建表单,验证提交的数据并通过表单访问它们将是一个executeCreate ,请参见此处的示例( executeCreateprocessForm动作类中的方法)。

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

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