GithubHelp home page GithubHelp logo

chasegiunta / guestentries Goto Github PK

View Code? Open in Web Editor NEW

This project forked from craftcms/guest-entries

4.0 4.0 1.0 43 KB

Create. edit, and delete entry submissions with Craft, anonymously.

License: MIT License

PHP 87.23% HTML 12.77%

guestentries's Introduction

Guest Entries plugin for Craft

This is a fork of Pixel & Tonic's Guest Entries plugin. This plugin allows you to save, edit, and delete guest entries from the front-end of your website.

Requirements

This plugin requires Craft 2.0+.

Installation

To install Guest Entries, follow these steps:

  1. Upload the guestentries/ folder to your craft/plugins/ folder.
  2. Go to Settings > Plugins from your Craft control panel and enable the Guest Entries plugin.
  3. Click on “Guest Entries” to go to the plugin’s settings page, and configure the plugin how you’d like.

Settings

From the plugin settings page, you can configure which sections you want to allow guest entry submission to along with who the default author will be.

Every user you see in the default author list has “createEntry” permissions for the section.

Usage

Your guest entry template can look something like this:

<form method="post" action="" accept-charset="UTF-8">
    {{ getCsrfInput() }}
    <input type="hidden" name="action" value="guestEntries/saveEntry">
    <input type="hidden" name="redirect" value="success">
    <input type="hidden" name="sectionId" value="3">

    <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="Publish">
</form>

If you need to edit the entry, be sure to include the entry ID <input type="hidden" name="entryId" value="123">. If you need to delete an entry, include the entry ID, as above, change the action input's value to guestEntries/deleteEntry.

You will need to adjust the hidden “sectionId” input to point to the section you would like to post guest entries to.

If you have a “redirect” hidden input, the user will get redirected to it upon successfully saving the entry.

If there is a validation error on the entry, then the page will be reloaded with an entry variable available to it, set to an EntryModel describing the submitted entry. You can fetch the posted values from that variable, as well as any validation errors via entry.getError(), getErrors(), or getAllErrors(). (The name of this variable is configurable via the entryVariable config setting.)

Submitting via Ajax

Submitting a guestEntries/saveEntry form action via ajax responds with an object with the following keys:

  • success (boolean) - true
  • id (string) - id of the entry saved
  • title (string) - title of the entry saved
  • cpEditUrl (string) - returned if the request came from the control panel
  • authorUsername (string) - author username of the entry saved
  • dateCreated (string) - ISO 8601 standard date and time format of the date the entry was created
  • dateUpdated (string) - ISO 8601 standard date and time format of the date the entry was updated
  • postDate (string) - if the entry is disabled by default, this will be null
  • url (string) - live URL of the entry saved if it has a URL

The guestEntries.beforeSave event

Other plugins can be notified right before a guest entry is saved with the Guest Entries plugin, and they are even given a chance to prevent the entry from saving at all.

class SomePlugin extends BasePlugin
{
    // ...

    public function init()
    {
        craft()->on('guestEntries.beforeSave', function(GuestEntriesEvent $event) {
            $entryModel = $event->params['entry'];

            // ...

            if ($isVulgar)
            {
                // Setting $isValid to false will cause a validation error
                // and prevent the entry from being saved.

                $entryModel->addError('title', 'Do you kiss your mother with those lips?');
                $event->isValid = false;
            }

            if ($isSpam)
            {
                // Setting $fakeIt to true will make things look as if the entry was saved,
                // but really it wasn't

                $event->fakeIt = true;
            }
        });
    }
}

guestEntries.success and guestEntries.error events

Plugins can also listen to success and error events that get fired when a guest entry successfully gets saved or not.

Each of them has an entry parameter where you can access the EntryModel of the guest entry.

Additionally, success has a faked parameter so you can tell whether the success was a real one or a faked one.

Configuration

Guest Entries has the following config settings:

  • entryVariable - The name of the variable that submitted entries should be assigned to when the template is reloaded in the event of a validation error. Default is 'entry'.

To override Guest Entries’ config settings, create a new file in your craft/config folder called guestentries.php, at craft/config/guestentries.php. That file should returns an array of your custom config values.

<?php

return array(
    'entryVariable' => 'guestEntry',
);

Changelog

1.5.2

  • Limit the data returned on a successful save for an AJAX request. This removes potentially sensitive data from being returned.

1.5.1

  • Fixed a PHP error that would occur if the guest entry failed validation.

1.5.0

  • Add onSuccess and onError events.

1.4.0

  • Updated to take advantage of new Craft 2.5 plugin features.

1.3.1

  • Fixed a bug where the “Validate Entry” setting Lightswitch would reset to on position after being set to off.

1.3

  • Added the entryVariable config setting.

1.2.2

  • Fixed a bug where validation would fail when saving guest entries for sections/entry types with dynamic titles.

1.2.1

  • Added the ability to explicitly set whether validation is required on a per-section basis.

1.2

  • Added support for the Client user when running Craft Client.

1.1

  • Added GuestEntriesService.php to raise an ‘onBeforeSave’ event before saving a new guest entry.

1.0

  • Initial release

guestentries's People

Contributors

angrybrad avatar brandonkelly avatar chasegiunta avatar roberskine avatar furioursus avatar iainhenderson avatar kylebakerrockit avatar selvinortiz avatar

Stargazers

Oleg Tishkin avatar Fred Carlsen avatar Paul Frost avatar Ian Nebbiolo avatar

Watchers

Paul Frost avatar James Cloos avatar  avatar  avatar

Forkers

fewagency

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.