{"id":1774,"date":"2020-12-12T18:17:33","date_gmt":"2020-12-12T09:17:33","guid":{"rendered":"http:\/\/www.white-box.biz\/?p=1774"},"modified":"2023-01-11T20:55:45","modified_gmt":"2023-01-11T11:55:45","slug":"cakephp-post%e5%87%a6%e7%90%86%e3%81%be%e3%81%a8%e3%82%81","status":"publish","type":"post","link":"https:\/\/www.white-box.biz\/?p=1774","title":{"rendered":"cakephp post\u51e6\u7406\u307e\u3068\u3081"},"content":{"rendered":"<p>view\u3067\u9805\u76ee\u540d\u3092\u7f85\u5217\u3059\u308b\u306e\u304c\u3081\u3093\u3069\u304f\u3055\u3044\u5834\u5408<\/p>\n<blockquote><p>&lt;?php<br \/>\necho $this-&gt;Form-&gt;create(&#8216;\u30e2\u30c7\u30eb\u540d&#8217;);<br \/>\necho &#8216;&lt;div class=&#8221;form-inline&#8221;&gt;&#8217;;<br \/>\necho &#8216;&lt;div&gt;&lt;button class=&#8221;btn btn-primary btn-sm&#8221; type=&#8221;submit&#8221; name=&#8221;action&#8221; value=&#8221;save&#8221;&gt;\u4fdd\u5b58&lt;\/button&gt;&lt;\/div&gt;&#8217;;<br \/>\necho &#8216;&lt;\/div&gt;&#8217;;<br \/>\n$datas = $this-&gt;Form-&gt;value()[&#8216;value&#8217;];<br \/>\n\/\/\u53c8\u306f $datas = $this-&gt;request-&gt;data[&#8216;\u30e2\u30c7\u30eb\u540d&#8217;];<br \/>\nforeach($datas as $key=&gt;$val){<br \/>\nif(&#8216;password&#8217;==$key) continue;<br \/>\necho $this-&gt;Form-&gt;input($key);<br \/>\n}<br \/>\necho $this-&gt;Form-&gt;end();<br \/>\n?&gt;<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<p>view\u306eselect\u8981\u7d20\u306e\u9078\u629e\u80a2\u3092controller\u3067\u8a2d\u5b9a<\/p>\n<blockquote><p>\u25a0controller<br \/>\n$this-&gt;request-&gt;data[&#8216;\u30e2\u30c7\u30eb\u540d&#8217;][&#8216;op&#8217;][&#8216;\u30e2\u30c7\u30eb\u540d.\u30ab\u30e9\u30e0\u540d&#8217;] = [&#8216;0&#8217;=&gt;&#8217;\u9078\u629e\u80a21&#8242;,&#8217;1&#8217;=&gt;&#8217;\u9078\u629e\u80a22&#8217;];<br \/>\n\u25a0view<br \/>\necho $this-&gt;Form-&gt;input(&#8216;\u30ab\u30e9\u30e0\u540d&#8217;, [&#8216;class&#8217;=&gt;&#8217;form-control&#8217;,&#8217;options&#8217;=&gt;$this-&gt;request-&gt;data[&#8216;op&#8217;][&#8216;\u30e2\u30c7\u30eb\u540d.\u30ab\u30e9\u30e0\u540d]]);<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<p>post\u306e\u4ed5\u65b9<\/p>\n<p>\u2460\u666e\u901a\u306bform\u3067\u56f2\u3093\u3060\u8981\u7d20\u3067post<\/p>\n<blockquote><p>\u25a0view<br \/>\n&lt;?php<br \/>\necho $this-&gt;Form-&gt;create(&#8216;\u30e2\u30c7\u30eb\u540d&#8217;);<br \/>\necho &#8216;&lt;div&gt;&lt;button class=&#8221;btn btn-primary btn-sm&#8221; type=&#8221;submit&#8221; name=&#8221;action&#8221; value=&#8221;save&#8221;&gt;\u4fdd\u5b58&lt;\/button&gt;&lt;\/div&gt;&#8217;;<br \/>\necho $this-&gt;Form-&gt;input(\u2019\u30ab\u30e9\u30e0\u540d\u2019);<br \/>\necho $this-&gt;Form-&gt;end();<br \/>\n?&gt;<br \/>\n\u25a0controller<br \/>\n$this-&gt;request-&gt;data[&#8216;\u30e2\u30c7\u30eb\u540d&#8217;]\u306b\u5165\u3063\u3066\u3044\u308b\u3002<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<p>\u2461javascript\u3067\u7121\u7406\u3084\u308aform\u3092\u4f5c\u308a\u4efb\u610f\u306e\u8981\u7d20\u3092post<\/p>\n<blockquote><p>\u25a0view<br \/>\n$(&#8216;&lt;form\/&gt;&#8217;,{action:url&#8217;,method:&#8217;post&#8217;})<br \/>\n.append($(&#8216;&lt;input\/&gt;&#8217;,{type:&#8217;hidden&#8217;,name:&#8217;data[\u30e2\u30c7\u30eb\u540d][\u30ab\u30e9\u30e0\u540d1]&#8217;,value:\u50241}))<br \/>\n.append($(&#8216;&lt;input\/&gt;&#8217;,{type:&#8217;hidden&#8217;,name:&#8217;data[\u30e2\u30c7\u30eb\u540d][\u30ab\u30e9\u30e0\u540d2]&#8217;,value:\u50242}))<br \/>\n.append($(&#8216;&lt;input\/&gt;&#8217;,{type:&#8217;hidden&#8217;,name:&#8217;data[\u30e2\u30c7\u30eb\u540d][\u30ab\u30e9\u30e0\u540d3]&#8217;,value:\u50243}))<br \/>\n.append($(&#8216;&lt;input\/&gt;&#8217;,{type:&#8217;hidden&#8217;,name:&#8217;data[\u30e2\u30c7\u30eb\u540d][\u30ab\u30e9\u30e0\u540d4]&#8217;,value:\u50244}))<br \/>\n.appendTo(document.body).hide().submit().remove();<br \/>\n\u25a0controller<br \/>\n$this-&gt;request-&gt;data[&#8216;\u30e2\u30c7\u30eb\u540d&#8217;]\u306b\u5165\u3063\u3066\u3044\u308b\u3002<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<p>\u2462ajax\u3067form\u306b\u56f2\u307e\u308c\u305f\u8981\u7d20\u3092post<\/p>\n<blockquote><p>\u25a0view<br \/>\nvar postdata =\u00a0$(formid).serialize();<br \/>\nvar param = {url: url, type: &#8216;post&#8217;,data:postdata};<br \/>\n$.ajax(param)<br \/>\n\u25a0controller<br \/>\n$this-&gt;request-&gt;data[&#8216;\u30e2\u30c7\u30eb\u540d&#8217;]\u306b\u5165\u3063\u3066\u3044\u308b\u3002<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<p>\u2463ajax\u3067\u4efb\u610f\u306e\u8981\u7d20\u3092post<\/p>\n<blockquote><p>\u25a0view<br \/>\nvar postdata = {\u30e2\u30c7\u30eb\u540d:{\u30ab\u30e9\u30e0\u540d:\u50241}};<br \/>\nvar param = {url: url, type: &#8216;post&#8217;,data:postdata};<br \/>\n$.ajax(param)<br \/>\n\u25a0controller<br \/>\n$this-&gt;request-&gt;data[&#8216;\u30e2\u30c7\u30eb\u540d&#8217;]\u306b\u5165\u3063\u3066\u3044\u308b\u3002<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<p>\u2464ajax\u3067form\u306b\u56f2\u307e\u308c\u305f\u8981\u7d20\u3068\u4efb\u610f\u306e\u8981\u7d20\u3092post<\/p>\n<blockquote><p>\u25a0view<br \/>\nvar hoge = {};<br \/>\nhoge[&#8216;post&#8217;] = $(formid).serializeArray()<br \/>\nhoge[&#8216;handson&#8217;]=$(&#8216;#hot1&#8217;).handsontable(&#8216;getSourceData&#8217;);<br \/>\nvar postdata = {data:JSON.stringify(hoge)};<br \/>\nvar param = {url: url, type: &#8216;post&#8217;,data:postdata};<br \/>\n$.ajax(param)<\/p>\n<p>\u25a0controller<br \/>\n$decoded = json_decode($this-&gt;request-&gt;data,true);<br \/>\n$handson = $decoded[&#8216;handson&#8217;];<br \/>\n$postparam = $decoded[&#8216;post&#8217;];<br \/>\n\/\/\u4e0b\u8a18\u3067cakephp\u306e$this-&gt;request-data\u914d\u4e0b\u306e\u5f62\u306b\u5909\u63db<br \/>\n$cakepostdate = [];<br \/>\nforeach($postparam as $val){<br \/>\nif(strpos($val[&#8216;name&#8217;], &#8216;data[&#8216;) !== 0) continue;<br \/>\npreg_match_all(&#8216;\/\\[(.*?)\\]\/&#8217;, $val[&#8216;name&#8217;], $matches);<br \/>\n$key = implode(&#8216;.&#8217;,$matches[1]);<br \/>\nif($this-&gt;Common-&gt;endsWith($val[&#8216;name&#8217;],'[]&#8217;)){<br \/>\n$key = substr($key, 0, -1);<br \/>\nif(!is_array($cakepostdate[$key])){<br \/>\nunset($cakepostdate[$key]);<br \/>\n}<br \/>\n$cakepostdate[$key][] = str_replace(&#8220;\\t&#8221;,&#8221;&#8221;,trim($val[&#8216;value&#8217;]));<br \/>\n}else{<br \/>\n$cakepostdate[$key] = str_replace(&#8220;\\t&#8221;,&#8221;&#8221;,trim($val[&#8216;value&#8217;]));<br \/>\n}<br \/>\n}<br \/>\n$cakepostdate = Hash::expand($cakepostdate);<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>view\u3067\u9805\u76ee\u540d\u3092\u7f85\u5217\u3059\u308b\u306e\u304c\u3081\u3093\u3069\u304f\u3055\u3044\u5834\u5408 &lt;?php echo $this-&gt;Form-&gt;create(&#8216;\u30e2\u30c7\u30eb\u540d&#8217;); echo &#8216;&lt;div class<a href=\"https:\/\/www.white-box.biz\/?p=1774\"><b>[\u30fb\u30fb\u30fb\u7d9a\u304d\u3092\u8aad\u3080]<\/b><\/a><\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"_links":{"self":[{"href":"https:\/\/www.white-box.biz\/index.php?rest_route=\/wp\/v2\/posts\/1774"}],"collection":[{"href":"https:\/\/www.white-box.biz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.white-box.biz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.white-box.biz\/index.php?rest_route=\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.white-box.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1774"}],"version-history":[{"count":6,"href":"https:\/\/www.white-box.biz\/index.php?rest_route=\/wp\/v2\/posts\/1774\/revisions"}],"predecessor-version":[{"id":1781,"href":"https:\/\/www.white-box.biz\/index.php?rest_route=\/wp\/v2\/posts\/1774\/revisions\/1781"}],"wp:attachment":[{"href":"https:\/\/www.white-box.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1774"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.white-box.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1774"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.white-box.biz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1774"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}