On Mon, Jun 21, 2010 at 9:58 AM, Jon Bennett <[email protected]> wrote:
> Hi bakers,
>
> With cakephp 1.3, is it possible to overwrite the value of $this->data
> used by the Form helper? I have some custom validation which when it
> fails I'd like to amend the data in the form manually.
>
> I could overwrite the variable and save the form, but it would be nice
> to let the user know and give them the option to confirm it.
That should work. The helper just uses whatever the controller's $data
array is set to.
If it's an edit form, make sure you're not resetting again by a find()
call before the method is done (and the form is reloaded).
function edit($id)
{
if (!empty($this->data))
{
if (validates and save)
{
do redirect
}
}
else if empty($this->data))
{
read the data into $this->data
}
// if validation/save failed, you'll pass through here again
// before reloading the form. Thus, the above else block is
// necessary to avoid resetting $data
}
Check out the new CakePHP Questions site http://cakeqs.org and help others with
their CakePHP related questions.
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en