简体   繁体   English

将表单值传递给CakePHP中的控制器操作参数

[英]Passing form values to controller action params in CakePHP

In my HTML form I need the URL output like this: "example.com/mycontroller/action/mike/apple" 在我的HTML表单中,我需要这样的URL输出:“ example.com/mycontroller/action/mike/apple”

  • When I submit form with "post" my form values are not visible and can be get through "_POST". 当我使用“发布”提交表单时,我的表单值不可见,可以通过“ _POST”获取。 I don't prefer this because it makes output like this: "example.com/mycontroller/action/" 我不喜欢它,因为它产生如下输出:“ example.com/mycontroller/action/”
  • When I submit with "get" my form becomes "example.com/mycontroller/action?type=mike&key=apple" 当我使用“获取”提交时,我的表格将变成“ example.com/mycontroller/action?type=mike&key=apple”
  • I also don't prefer to change form action with javascript, like: "onSubmit take value of select and append it to form action" Because I don't want this snippet be javascript dependent. 我也不希望使用javascript更改表单操作,例如:“ onSubmit接受select的值并将其附加到表单操作中”,因为我不希望此代码段与javascript相关。
  • I can submit form with "get" or "post" parse system variables of POST or GET and make a redirection. 我可以使用“ get”或“ post”提交表单来解析POST或GET的系统变量,然后进行重定向。 Like this: Redirect this "example.com/mycontroller/action?type=mike&key=apple" to this "example.com/mycontroller/action/mike/apple" But I didn't find this solution well designed. 像这样:将这个“ example.com/mycontroller/action?type=mike&key=apple”重定向到这个“ example.com/mycontroller/action/mike/apple”,但是我发现这个解决方案设计得不好。 Is it possible to pass form values with slashes (other than questiın marks) 是否可以使用斜杠(问号除外)传递表单值

     < form class="well form-horizontal" id="myform" method="get" action="/mycontroller/action" > <select name="type" id="type"> <option value="mike" selected="selected"> mickey bricks</option> <option value="albie">albert</option> </select> <input type="text" name="key" class="input-xlarge" id="key" required="required"> <button type="submit" class="btn btn-primary" id="submit"> submit </button> </form> 

If you make a POST form, it doesn't really matter where does it post to , what matters is where does it redirect. 如果您创建POST表单,则将其发布哪里并不重要,重要的是它将重定向哪里。 Many site searches redirect you to www.domain.com/search/search_terms so if this is a search form, there is nothing wrong with redirecting to ../action/mike/apple . 许多站点搜索将您重定向到www.domain.com/search/search_terms,因此,如果这是搜索表单,则重定向到../action/mike/apple并没有错。

Additionally, if it is a POST form, it will not be filled in by the search crawlers (or at least not to my knowledge), so again it shouldn't matter where does the form post to, what matters is the return value and where does it redirect. 此外,如果它是POST表单,那么搜寻爬虫将不会填写该表单(或者至少在我所知的范围内),因此,该表单向何处发布也无关紧要,返回值和它在哪里重定向。

It all really depends on what are you trying to accomplish. 这实际上取决于您要完成什么。

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

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