I have the following code on my blog, to check if a comment is spam
$tmp = new Comment();
$tmp->setName(urldecode($this->getRequest()->getCookie('commName')));
$tmp->setEmail(urldecode($this->getRequest()->getCookie('commEmail')));
$tmp->setUrl(urldecode($this->getRequest()->getCookie('commUrl')));
$this->form = new CommentAddForm($tmp);
if ($request->isMethod('post'))
{
$this->form->bind($request->getParameter('comment'));
if ($this->form->isValid())
{
$key = sfConfig::get('akismet_api_key');
$data = array(
'blog' => '...',
'user_ip' => $this->getRequest()->getHttpHeader('addr','remote'),
'user_agent' => $_SERVER['HTTP_USER_AGENT'],
'referrer' => $_SERVER['HTTP_REFERER'],
'comment_type' => 'comment',
'comment_author' => $this->form->getObject()->getName(),
'comment_author_email' => $this->form->getObject()->getEmail(),
'comment_author_url' => $this->form->getObject()->getUrl(),
'comment_content' => $this->form->getObject()->getComment()
);
$isSpam = myLib::akismet_comment_check($key, $data);
(…)
But I just noticed that I’m bombarded with spam, and while testing on local it seems that $this->form->getObject()->getName() doesn’t return the name in the form, but the previous name used, the one saved in a cookie !
I looked at the changelog for symfony 1.4.19, but didn’t see anything that would relate to that, it may be a coincidence.
Calling
$form->bind()method only populatesvaluesproperty of the form. It does not hydrate the form’s object. That is done when saving the form. You probably want to call$form->updateObject()which is called during save. That will populate the object with the form’s values.