I would like to give users the option to "Save as Draft" or "Publish" at the end of a Channel Forms entry.
Is there a way to attach a status to a button? Has anyone done something like this?
ExpressionEngine® Answers is a question and answer site for administrators, end users, developers and designers for ExpressionEngine® CMS. It only takes a minute to sign up.
Sign up to join this communitySubmit buttons can have a name and value, too. And if you use actual <button>
elements, the value can be different from what's displayed on the button (unlike using <input type="button" />
).
Take this simplified example (just using a regular old form):
<form action="" method="post">
<input type="text" name="title" />
<button type="submit" name="status" value="draft">Save as draft</button>
<button type="submit" name="status" value="open">Publish</button>
</form>
If you click the 'Save as draft' button, the form will send along status=draft
. If you click the 'Publish' button, the form will send status=open
instead. If you hit return in the text field (submitting the form), the value of the first submit-button will be posted.
This is true for any web form (or at least apache/php), so it should work for EE's Channel Form, too.
Alternatively, you could just use a single save-button and add a checkbox to the form to enable 'save as draft', and apply the status to that field, ie.
<label>
<input type="checkbox" name="status" value="draft">
save as draft
</label>
...and status=draft
will be posted if the checkbox is ticked.