2

when a user with no permission to publish is submitting a blank entry, the entry is saved anyway without any errors.

Here is the permissions set to the user group:

permissions

I have few required field as showed below:

new entry

And very sadly, the entry is saved as draft, entitled "New Entry":

entry is saved

This can't be a feature, is it?

5

As carlcs said, this is already working as expected. Craft only enforces content validation rules for enabled entries (not including drafts), and most people prefer that behavior.

If you want to change that behavior, you can write a plugin that provides its own entry validation logic, by latching onto the entries.onBeforeSaveEntry event. Just put this in your plugin’s primary class:

public function init()
{
    craft()->on('entries.beforeSaveEntry', function(Event, $event) {
        /** @var EntryModel $entry */
        $entry = $event->params['entry'];

        // If the entry is disabled, the content won't be validated automatically
        if (!$entry->enabled)
        {
            $validates = craft()->content->validateContent($entry);

            if (!$validates)
            {
                // Add the content validation errors
                $entry->addErrors($entry->getContent()->getErrors());

                // Prevent the entry from getting saved
                $event->performAction = false;
            }
        }
    });
}
|improve this answer|||||
4

As other answers have touched on, the behaviour you're seeing is by design.

I've written a plugin called Always Validate which will make Craft validate all disabled entries and categories – including entry drafts or entries saved by users not permitted to publish – which should solve your issue.

|improve this answer|||||
3

That's the idea behind Drafts, to store entries not yet ready to publish, unfinished ones so to speak.

I think it does make sense to not validate the fields. Good feature!

|improve this answer|||||
  • Well, in my case it does not make sense. The title should be at least mandatory, because the user should able to identify the entry a way or an other in the list. This also means that that user group will not have the feeling that they are responsible of the content, but they are. – pvledoux Mar 10 '16 at 9:51
  • What if they haven't decided on a title yet. You can always tell them to enter one? If it's really important for you (you didn't tell the whole story yet, so there might be reasons), you could write a simple plugin that listens to onBeforeSaveEntry events. – carlcs Mar 10 '16 at 9:55
  • Ok, with the responsibility reason, you're onto something. But there should be other ways to handle it than restricting the Drafts feature. I mean, those users want to have their content published eventually, so you need to find a way to make them clear to put some effort into creating or editing entries. – carlcs Mar 10 '16 at 10:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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