18

I'd like to create a form for users to load events (that I will moderate and publish).

How do I do this?

1 Answer 1

18

If the users are authenticated and have permission to post to the event section, you would use an entry form to accept posts from the front end.

Example from the above linked page...

<form method="post" action="" accept-charset="UTF-8">
    <input type="hidden" name="action" value="entries/saveEntry">
    <input type="hidden" name="redirect" value="viewentry/{id}">
    <input type="hidden" name="sectionId" value="10">

    <label for="title">Title</label>
    <input id="title" type="text" name="title">

    <label for="body">Body</label>
    <textarea id="body" name="fields[body]"></textarea>

    <input type="submit" value="Submit">
</form>

Deliberately removed from the example above is this <input type="hidden" name="enabled" value="0">, since it'd be redundant and make it more obvious how one might tamper with the form. Setting enabled to 1 would allow submitted posts to go live immediately.

If you'd like to accept guest entries you can use Pixel and Tonic's GuestEntries plugin. Keep in mind that the submissions will still be assigned to the Craft author (user with appropriate permissions) that you designate. The front-end form would look nearly identical, with a hidden action of guestEntries/saveEntry...

<form method="post" action="" accept-charset="UTF-8">
    <input type="hidden" name="action" value="guestEntries/saveEntry">
    <input type="hidden" name="redirect" value="viewentry/{id}">
    <input type="hidden" name="sectionId" value="10">

    <label for="title">Title</label>
    <input id="title" type="text" name="title">

    <label for="body">Body</label>
    <textarea id="body" name="fields[body]"></textarea>

    <input type="submit" value="Submit">
</form>

The plugin's settings let you define default authors and entry statuses for each channel:

GuestEntries plugin settings

GuestEntries also adds a guestEntries.beforeSave event that you can hook into with your own plugin and further act on submissions before they're added to the database.

7
  • 1
    wouldn't you want to set enabled to false/0? He said he wants to review/moderate before publishing. Commented Jun 12, 2014 at 5:04
  • Also, if you want to be notified when someone submits data, you would need a plugin that uses the Craft CMS event for entry saved: buildwithcraft.com/docs/plugins/hooks-and-events#events Commented Jun 12, 2014 at 5:06
  • Updated 'enabled' setting in the example, thanks Luke.
    – Matt Stein
    Commented Jun 12, 2014 at 5:35
  • 1
    @Matt, please add to your answer that it is also possible to allow anonymous entry submissions using the GuestEntries Plugin.
    – carlcs
    Commented Jun 12, 2014 at 7:50
  • 2
    If you don't want the entry to be enabled, you can just remove the whole input altogether. Form inputs can easily be tampered with though, so what’s really important here is that your users don’t have permission to publish live entries in this section. That will trump whatever the "enabled" param is set to. Commented Jun 12, 2014 at 12:24

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.