Re: How to keep Cake from trying to save certain form inputs ?
On Thu, Oct 7, 2010 at 1:57 AM, EJ wrote: > Thanks for your help cricket! > Something else might be going on as it seems to break unless I clear > those values out. Could it be that the values don't match the column definition? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: How to keep Cake from trying to save certain form inputs ?
Thanks for your help cricket! Something else might be going on as it seems to break unless I clear those values out. I'll try to do some more debugging but this definitely gives me a clue. I really appreciate your help. On Oct 6, 9:00 pm, cricket wrote: > On Tue, Oct 5, 2010 at 3:25 PM, EJ wrote: > > Folks, > > > I have a newbie question: > > > I have a form that has certain inputs that just need to be ignored. > > For example a "User" may be associated (e.g. via HABTM) with a > > particular "City" > > The "City" may be associated with a "State" but I don't need an > > association between "State" and "User". > > > When I show the registration form, I want to use AJAX to show you a > > list of states and once you select a state show you the list of cities > > to avoid an overly-long list of cities. But when the form is submitted > > I don't want Cake to try to save the state since there's no direct > > association between user and state. > > > Is there a magic setting in the form input to keep it from being set? > > Or do I have to handle it and null it out in the controller? > > Model::save() strips them out for you by first checking for it in the > schema using hasField(). If it's not present, it's tossed out. > > http://api.cakephp.org/view_source/model/ > > 1307 foreach ($v as $x => $y) { > 1308 if ($this->hasField($x) && (empty($this->whitelist) || > in_array($x, $this->whitelist))) { > 1309 list($fields[], $values[]) = array($x, $y); > 1310 } > 1311 } > > The $whitelist there is used for when there are fields which do belong > to the model but, for whatever reason, you don't want to save their > values if present in the data. In that case, you'd pass an array of > the ones you DO want written to the DB as the 3rd param to > save();http://api.cakephp.org/class/model#method-Modelsave Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: How to keep Cake from trying to save certain form inputs ?
On Tue, Oct 5, 2010 at 3:25 PM, EJ wrote: > Folks, > > I have a newbie question: > > I have a form that has certain inputs that just need to be ignored. > For example a "User" may be associated (e.g. via HABTM) with a > particular "City" > The "City" may be associated with a "State" but I don't need an > association between "State" and "User". > > When I show the registration form, I want to use AJAX to show you a > list of states and once you select a state show you the list of cities > to avoid an overly-long list of cities. But when the form is submitted > I don't want Cake to try to save the state since there's no direct > association between user and state. > > Is there a magic setting in the form input to keep it from being set? > Or do I have to handle it and null it out in the controller? Model::save() strips them out for you by first checking for it in the schema using hasField(). If it's not present, it's tossed out. http://api.cakephp.org/view_source/model/ 1307 foreach ($v as $x => $y) { 1308if ($this->hasField($x) && (empty($this->whitelist) || in_array($x, $this->whitelist))) { 1309list($fields[], $values[]) = array($x, $y); 1310} 1311} The $whitelist there is used for when there are fields which do belong to the model but, for whatever reason, you don't want to save their values if present in the data. In that case, you'd pass an array of the ones you DO want written to the DB as the 3rd param to save(); http://api.cakephp.org/class/model#method-Modelsave Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
How to keep Cake from trying to save certain form inputs ?
Folks, I have a newbie question: I have a form that has certain inputs that just need to be ignored. For example a "User" may be associated (e.g. via HABTM) with a particular "City" The "City" may be associated with a "State" but I don't need an association between "State" and "User". When I show the registration form, I want to use AJAX to show you a list of states and once you select a state show you the list of cities to avoid an overly-long list of cities. But when the form is submitted I don't want Cake to try to save the state since there's no direct association between user and state. Is there a magic setting in the form input to keep it from being set? Or do I have to handle it and null it out in the controller? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en