Search code examples
expressionenginesafecracker

Clone entry in expressionengine with safecracker


I have an expressionengine template for frontend users using safecracker to create entries. ex: http://domain.com/index.php/create. After user creates an entry, the entry can be edited by going to http://domain.com/index.php/create/my_entry where my_entry is the entry user created. My question is can i provide the user an option to clone an entry. What is the best way to clone. I can't think of an easy way to do this.


Solution

  • I haven't tried this, but you could try creating a new template - say, /index.php/clone/ - that you'd link to with the url_title of the entry to be cloned after it (e.g., /index.php/clone/my_entry). Then use a channel:entries tag with url_title="{segment_2}" to get the values of all the existing entry's fields, and nest an {exp:safecracker} tag inside of it?

    {exp:channel:entries channel="my_channel" url_title="{segment_2}"}
    
        {exp:safecracker channel="my_channel"}
            <input name="title" type="text" value="{title} /> 
            <input name="my_custom_field" type="text" value="{my_custom_field}" /> 
            ... etc ...
            <input type="submit" value="Submit" />
        {/exp:safecracker}
    
    {/exp:channel:entries}
    

    Worth a shot anyway.