HABTM form validation in CakePHP

前端 未结 7 1375
我在风中等你
我在风中等你 2020-12-03 06:33

I have a Projects table and a Users table which are linked by a HABTM relation. In the \"add\" new Project page I have a multiple checkbox section to select Users for the ne

7条回答
  •  旧巷少年郎
    2020-12-03 06:47

    teknoid's blog has a pretty in depth solution to your issue here. The most Cakey way of doing this would be to add custom validation to your model, as you mention in your comment above. Check out http://teknoid.wordpress.com/2008/10/16/how-to-validate-habtm-data/

    From the article, where Tag HABTM Post (:: Project HABTM Users):

    First, we validate the Tag model, by using the data from the form to ensure that at least one Tag was selected. If so, we save the Post and the relevant Tags.

提交回复
热议问题