benhowdle89
benhowdle89

Reputation: 37464

CakePHP if form field invalidates then values aren't remembered

I'm using model based validation with CakePHP and if the field invalidates then the values aren't remembered in the form.

Is there a built in method/way to prevent this and have Cake remember the users entered values?

Upvotes: 1

Views: 241

Answers (2)

Oldskool
Oldskool

Reputation: 34837

It should remember the data wheter it validates or not. Are you using full names for your fields including the model? Like this:

echo $this->Form->input('Model.fieldname');

Rather than the "short" notation with just the fieldname, like:

echo $this->Form->input('fieldname');

That should work in pretty much any case.

Upvotes: 0

Rob Wilkerson
Rob Wilkerson

Reputation: 41236

Are you redirecting? The easiest way I've found to do this is that, if the model doesn't validate, then allow the processing to drop through and display the same page as part of the answering request. As soon as you redirect, the errors are lost. As long as you're using the Form helper, it should pre-populate the form from the values in $this->data.

You didn't provide much in the way of detail, but hopefully I understood your question correctly.

Upvotes: 3

Related Questions