3

A two part question here.

  1. When saving an entry from front-end entry form, can I designate it to save as a draft? If so, how?

  2. If the answer to #1 is true, can I query against that to list only entries that are not in 'draft' mode.

2 Answers 2

4
  1. Yes. Kind of. Have you had a look at the Entry Form example in the docs? It looks like Craft will always need an entry to begin with, so you can't have a draft version without first creating a normal entry. That being said, you can set this new this entry as disabled, which also can be queried against by using

    craft.entries.status('disabled')

  2. I cannot see a documented example on how to list drafted entries, though.

Either way, to build on the Entry Form example, instead of having the action set to entries/saveEntry, change it to entryRevisions/saveDraft.

Something like:

<input type="hidden" name="action" value="entryRevisions/saveDraft">
<input type="hidden" name="redirect" value="draft?id={id}&draft={draftId}">
<input type="hidden" name="sectionId" value="1" />
<input type="hidden" name="enabled" value="0">

Note that you're now posting to the EntryRevisionsController@saveDraft, and that I here set entries to be disabled by default.

Does having them disabled help you do what you want, or do they have to be in Draft mode for some reason?

2
  • I have all entries submitted by frontend entry form disabled until an editor reviews them and publishes them. What I am looking for is a way to save an entry and flag it as a draft so that I can 1) not display it to the editor (again a frontend activity) and 2) the user can still save their work. I am thinking about adding a custom field and using that to query off of. Then creating another submit button name="fields[draftMode]" value="draft". Thoughts on this approach? Commented Sep 17, 2014 at 22:23
  • Sounds good. The P&T guys might have some tips on how to use those drafts in that way, but if not, I would also go for a custom field. Commented Sep 17, 2014 at 22:29
2

Old Question I know, but kept coming across it and I've been digging around as I had the same use case.

With regards, to Q1; if you don't give the user's group permission to publish live changes, their new entries will go in as disabled entries (Not a draft, but disabled entries ready for moderation).

Once the admin approves, the entry will be open and the user will not be able to update it. (They receive a permission denied message) You can however use the code as Fred posted to send the action to entryRevisions/saveDraft and that will store a proper 'draft' in Craft, without affecting the live entry.

It's not documented, but after poking around I found and tested a way of retrieving drafts by entry ID on the front-end;

{% set drafts = craft.entryRevisions.getDraftsByEntryId(229) %}

{% for draft in drafts %}
    <h2>{{ draft.title }}</h2>
    ...
{% endfor %}

You can then check for existing drafts and prevent the user submitting further changes until the draft has been approved/deleted.

Hopefully someone will find this useful!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.