-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi David,


this is how I would do it:

copy your edit method and rename it to "copy". Like with edit you fetch
the data which should be cloned and show then in a view "copy.ctp" which
has a form like for adding a new record.
Then when the user submits you call your copy method again in the "hey I
have post data" fork and save it as a new record by unsetting a probably
exiting id.

That should do it.

HTH!
Anja



Am 14.08.2013 20:22, schrieb David Carr:
> Here's what I am trying to accomplish:
> 
> A user fills out a form, saves a record.  At some later date they wish to 
> "clone" this record, but may want to make a few tweaks.  This "clone" 
> functionality should direct them to a form that is pre-filled with the 
> previous record's data so that they can review it, edit as needed, and 
> submit it as a new record.
> 
> What I'm trying:
> 
> I've modified my add() function to accept a parameters:
> 
> function add($cloneid = NULL)
> 
> Then created a Clone link that sends them to <site>/model/add/<id>
> 
> Then, I get the data from that model:
> 
> $clone_source = $this->Model->findById($cloneid);
> $this->data['Model']['field1'] = $clone_source['Model']['field1'];
> 
> and so on.  Based on Google searching and other posts, this should work. 
>  But what actually happens is that upon clicking the 'Clone' link, the user 
> is directed and the form submits itself immediately (failing to save the 
> record, since it fails validation) and the user never actually sees the 
> form.
> 
> What am I doing wrong?  (Also I should note, there are relational models 
> present, but I don't think this should be the cause of any problems...I 
> hope).
> 

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAlILzzsACgkQbOdiIJzHNKHLNQCgrshOiC1PR3d3fC5R033EBvqF
1fkAn2/8z7qSKbalW6aEdYHIQI0ymhhm
=RTV3
-----END PGP SIGNATURE-----

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to