Stephen Watkins
Stephen Watkins

Reputation: 25765

Mysterious Invalid Form in Symfony

I am using symfony 1.4 and am trying to submit a comment through a form (with an embedded user form). I have all the validators in place, but even though all the data is valid, the 'view' keeps coming up as orange and the form does not save. When I try to see details, it just shows the comment form as orange, but all the fields below it are just fine.

I'm very confused as to what is going on. Can anyone help?

Upvotes: 1

Views: 2527

Answers (2)

Jeremy Kauffman
Jeremy Kauffman

Reputation: 10413

It looks like you've got this sorted out, but I wanted to share a handy debugging method we put in our BaseForm class:

public function debug()
{
  if (sfConfig::get('sf_environment') != 'dev')
  {
    return;
  }
  foreach($this->getErrorSchema()->getErrors() as $key => $error)
  {
    echo '<p>' . $key . ': ' . $error . '</p>';
  }
}

This is an easy way to see all the errors on a form, even if they're for hidden elements or not getting rendered properly. By checking that we're in the dev environment, we also don't have to worry if we leave it in production code.

Upvotes: 9

greg0ire
greg0ire

Reputation: 23255

Try using var_dump() on the error schema of your form, this should give you more information on the errors.

Upvotes: 1

Related Questions