Reputation: 6555
A quick question. I have a symfony form. When I save the form, I want my created_by field to be set automatically on save.
So, I'm passing the current user id as an option in the form:
$this->form = new ContractForm(null,array("created_by"=>$this->getUser()->getId()));
And in the configure method of the form class I have:
$this->setDefault('created_by', $this->getOption("created_by"));
If I had a created_by widget and set it to hidden, this would work great, however, I don't want to have a field displayed as a user could easily manipulate using firebug or other tools alike.
So my question to you, how do I save a column value if the field does not exist as a widget?
Upvotes: 1
Views: 3262
Reputation: 394
I suggest you can use this behaviour on your class sfDoctrineActAsSignablePlugin.
Upvotes: 0
Reputation: 405
Or in your ContractForm class you can add to configure()
$this->widgetSchema['created_by'] = new sfWidgetFormInputText(array('default' => $this->getUser()->getId()));
Upvotes: 0
Reputation: 56
You dont need to have a widget for this, just in the configure method of your form call.
<?php
$this->getObject()->setCreatedBy($this->getOption('created_by'));
?>
There really is no need to overwrite a method.
Also for this to work youd have to initiate your form like this
<?php
$this->form = new ContractForm(new Contract(), array('created_by' => $this->getUser()->getId()));`
?>
Upvotes: 4