I have a form for gathering an email address, which corresponds to my User model. I’d like the form to also have a text field for an email message, but I don’t need the message saved to my database.
echo $this->Form->create('User', array('action' => 'invite','controller' => 'users'));
echo $this->Form->input('User.from', array('label'=>"Your email",'value'=>'your email','class'=>"",'type'=>'email'));
echo $this->Form->input('User.to', array('label'=>"Your friend's", 'value'=>"your friend's email",'class'=>"",'type'=>'email'));
echo $this->Form->textarea('User.message', array('label'=>'Your message', 'value'=>"some message"));
echo $this->Form->end(array('label'=>'Invite', 'class'=>'buttonstyle'));
This works, but only if I add a message column to my Users table, which I don’t need. I’d rather do something like this
echo $this->Form->textarea('message', array('label'=>'Your message', 'value'=>"some message"));
But that doesn’t work, I guess because “message” isn’t associated with a model. Is there a better way to do this?
what do you mean? of course that works, it is a pretty normal/trivial thing to have form fields that do not correspond to a db table field.
but your initial question is wrong. they usually always belong to a model (a scope so to speak), but not necessarily to a db table. you could even have them without any model related to it. But in most cases this does not make much sense.
the question is: do you need cake magic for them (auto-generate checkbox/textarea via input() based on the type)? do you want validation for them?
then you need to consider at least some schema entries for them.
see http://www.dereuromark.de/2011/12/15/tools-plugin-part-2-contact-form/ for an example how to work with _schema in the model to get all that (as you would with real db fields).
oh, and