craftcms / guest-entries

Accept anonymous entry submissions with Craft.
MIT License
106 stars 26 forks source link

Validation Error: Author Id cannot be blank #43

Closed sammcqueen closed 5 years ago

sammcqueen commented 5 years ago

I'm getting an author id validation error whenever I try to submit. Console is showing this:

[info][craft\services\Elements::saveElement] Element not saved due to validation error: Array
(
    [authorId] => Array
        (
            [0] => Author Id cannot be blank.
        )
)

I only have one user and have set this as the default author in the Guest Entries plugin settings. All other validations seem to be working correctly. Disabling validations in the settings does allow new entries. I've tried disabling CSRF protection with no joy.

Also tried adding a hidden authorId form input set to 1 just to test, but still receive the cannot be blank error.

Craft: 3.1.7

brandonkelly commented 5 years ago

I’m not able to reproduce this. Can you send in a request from your Craft Support dashboard widget, and reference this issue? Then we will be able to look into it with your site setup & templates.

sammcqueen commented 5 years ago

Not sure what it was but the latest update to the plugin has solved it. 👍

Geestig commented 5 years ago

I'm having a similar error. Updating did not help in my case. I get the following error:

{"success":false,"errors":{"authorId":["Author Id cannot be blank."]}}

This only happens when i'm logged out, else it works fine. I did declare a default author and it also passes when I turn of the validation option. I can't seem to find any other similar issues except for this one, but did not want to open a new issue with the same problem.

stenvdb commented 5 years ago

Can confirm this issue. Seems like the settings pages saves a wrong uid for the entry author, resulting in a null value being submitted in the save controller.

stenvdb commented 5 years ago

Ok, so the uid from the elements table is used instead of the one from the users table. I was able to fix my issue by changing the database name in line 226 in SaveController.php to (%users -> %elements): 'authorId' => Db::idByUid('{{%elements}}', $sectionSettings->authorUid),

Geestig commented 5 years ago

The above resolved my issue as well.

sammcqueen commented 5 years ago

Just tried whilst logged out and the issue persists. The above change to the Save Controller works so have made a pull request.

joeydi commented 5 years ago

Can confirm the @sammcqueen fix works.

sammcqueen commented 5 years ago

All credit to @stenvdb!

chadcrowell commented 5 years ago

Can confirm the @sammcqueen fix works.

brandonkelly commented 5 years ago

Just released v2.2.3 with @sammcqueen’s fix. Sorry about that!

robmcfadden commented 5 years ago

Note: I needed to re-save the Guest Entries plugin settings in the CP to get this fix to take.

m-rsmn commented 5 years ago

Indeed a very important caveat, just updating does not fix the issue, it's only fixed after hitting save in the plugin settings page.