Insert cakephp POST params into URL

2019-02-16 02:40发布

I have this form below which contains two checkboxes to sort some products:

<form id="FiltreExtraForm" action="" method="post" name="FiltreExtraForm">
    <input id="ProductsDeliveryPrice" type="checkbox" value="1" name="data[Products][delivery_price]"/>
    <input id="ProductsPicture" type="checkbox" value="1" name="data[Products][picture]"/>
</form>

After POST I do the filtering but I also want to add received parameters to URL E.g: /products/index/delivery_price:1/picture:0 . Is this possible. How can I do that?

Note: I don't want to use GET to send form info.

3条回答
不美不萌又怎样
2楼-- · 2019-02-16 03:10

Sounds like you are looking to do a Post/Redirect/Get.

Here are two examples of doing this in CakePHP:

The two main advantages of redirecting a POST to a GET request are:

  1. Users don't get the "Do you want to resubmit?" dialog if they refresh
  2. The resulting page/query can be bookmarked
查看更多
Juvenile、少年°
3楼-- · 2019-02-16 03:14

If I understand you correctly (and I'm not sure that I do), you can pass additional variables on the query string of the form's action quite easily. Conventionally, that might look like this:

<form id="FiltreExtraForm" action="/products/index?delivery_price=1&picture=0" method="post" name="FiltreExtraForm">

Using Cake, you should be able to do the same without the traditional query string if you'd rather (though the traditional method above will also work):

<form id="FiltreExtraForm" action="/products/index/delivery_price:1/picture:0" method="post" name="FiltreExtraForm"> 

I would recommend looking at the form helper or at least constructing the action URI using helpers, but this should get you what you're after.

查看更多
Viruses.
4楼-- · 2019-02-16 03:19

In the action to which you post, you could simply prepare the GET url and then redirect to this url. The action for that url then does the filtering.

查看更多
登录 后发表回答