cytech Posted April 14, 2009 Share Posted April 14, 2009 Hello, I'm a little confused(surprise) about how this exactly works... I am working on someones cakephp code(which is great fun ) and am trying to understand how some things work. There is a registration form, easy enough, now I added a new checkbox to the form and also added the new element in the db. When I submit the form all the variables come through (I did a dump of $this->data['User']) including my new checkbox name "Pd" with a value of 1 (checked). However; the database field remains 0, no matter what I do I can't get that field to change to one. Now, the code is using the generic ->save function. Should I be looking somewhere to see if the fields are specified? Like only save these fields and no others? Or, is there something else I should try to debug? Any advice would be very helpful. Quote Link to comment https://forums.phpfreaks.com/topic/154065-solved-cakephp-and-checkboxs/ Share on other sites More sharing options...
jcombs_31 Posted April 16, 2009 Share Posted April 16, 2009 I would suggest first check your data and forms with the scaffolding feature cake has. This should allow you to quickly troubleshoot if you have a problem with your logic or relationships. It is hard to answer your question without seeing more of your application. Quote Link to comment https://forums.phpfreaks.com/topic/154065-solved-cakephp-and-checkboxs/#findComment-811763 Share on other sites More sharing options...
cytech Posted April 16, 2009 Author Share Posted April 16, 2009 Hello, I will try to check out the scaffolding, whats weird is if I dump the data that is being passed to the "save" function, it shows my new variable there fine with a 1 (1=checked). It also saves the other information, so Its not causing a mysql error or anything. Looks like the new field is just being ignored hehe Thanks for some direction, I will try to dump that out and see what happens. Quote Link to comment https://forums.phpfreaks.com/topic/154065-solved-cakephp-and-checkboxs/#findComment-811777 Share on other sites More sharing options...
jcombs_31 Posted April 16, 2009 Share Posted April 16, 2009 Are you using form helpers or hard coding the form? Make sure your form names match the database field names. Quote Link to comment https://forums.phpfreaks.com/topic/154065-solved-cakephp-and-checkboxs/#findComment-811789 Share on other sites More sharing options...
cytech Posted April 16, 2009 Author Share Posted April 16, 2009 Form Helpers, the names match up perfectly. Db field name is "Pd" and form name comes out as "data[user][Pd]" it matches all of the other fields on the form. Quote Link to comment https://forums.phpfreaks.com/topic/154065-solved-cakephp-and-checkboxs/#findComment-811797 Share on other sites More sharing options...
jcombs_31 Posted April 16, 2009 Share Posted April 16, 2009 When you say you "dump" data, are you using the debug function to see the post values? Quote Link to comment https://forums.phpfreaks.com/topic/154065-solved-cakephp-and-checkboxs/#findComment-811813 Share on other sites More sharing options...
cytech Posted April 16, 2009 Author Share Posted April 16, 2009 Hey, Sorry, I mean var_dump, dumping the array of data being sent over to the save function. Quote Link to comment https://forums.phpfreaks.com/topic/154065-solved-cakephp-and-checkboxs/#findComment-811815 Share on other sites More sharing options...
cytech Posted April 21, 2009 Author Share Posted April 21, 2009 Okay... I have a bit more info now... If found where they had the global save function (model_php5.php). There is a function in here called hasField(). Now, for some reason the new element I created into the database will not get by this function. So upon further inspection I noticed the hasField function uses $this->_tableInfo within its in_array check. Now, if I var_dump $this->_tableInfo I notice ALL the fields from that table are there but NOT the new one I created, in fact none of the new fields I create show up. My first thought was, great I'm not using the same db or table, but the entry goes in to the right table and db, its just not recognizing the new fields I add. So, with that said is there an array setup somewhere to say include only these types of fields from this table? or anything like that? Any advice is GREATLY appreciated Quote Link to comment https://forums.phpfreaks.com/topic/154065-solved-cakephp-and-checkboxs/#findComment-815680 Share on other sites More sharing options...
cytech Posted April 23, 2009 Author Share Posted April 23, 2009 Well figured it out with some help... Cakephp had stored cached versions of the database and was using these cached versions to validate the fields on the form. Hence none of my new fields where used when saving. Gotta love it lol So I guess the moral of the story, checked cached versions of the db since cakephp I guess does this lol. Quote Link to comment https://forums.phpfreaks.com/topic/154065-solved-cakephp-and-checkboxs/#findComment-817270 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.