I have a symfony form with a few hidden fields that the user can't edit but are set automatically when they submit the form. The one field I can't seem to set is the userID. The form is secured so it requires authentication in order to display (sfDoctrineGuardPlugin).
What I'm looking for is for the form to set the "user_id" field to the currently logged in username. I have tried this in the class file.
if ($this->isNew() && ! $this->getSeller_Id())
{
$this->setSeller_Id($this->getUser()->getGuardUser()->getUsername());
}
But it always returns an error stating that there is no User field in the current table. I hope I explained that right.
Do not set user_id in hidden field. Someone could change it via firebug. I preffer to use this code inside proccessForm()
try this (edited):
$form = new YourForm();
$this->user = $this->getUser()->getObject();
$form->getObject()->setSellerId($this->user->getId());
$form->bind($request->getParameter($form->getName()));