Skip to main content
9 votes
Accepted

Craft 3 - Save new Entry with Relations (Categories/Assets)

This should be as simple as setting the relation field (category, asset, etc.) value on the entry as an array of related element IDs before saving. $entry->setFieldValue('categoryFieldHandle', [$...
Ben Croker's user avatar
  • 7,796
6 votes
Accepted

Problem saving new entry populated with setContentFromPost() while setContent() works

I believe that setContentFromPost can only be used to set the content of custom fields on an EntryModel, not standard fields such as title. Instead, you need to use $entry->getContent()->title ...
Steve Rowling's user avatar
6 votes
Accepted

Update form entry using the Guest Entries plugin

In Craft 3 / Guest Entries 2, you could pull this off without hacking Guest Entries by writing a module that listens to the beforeSaveEntry event, and sets the id on the entry. use Craft; use craft\...
Brandon Kelly's user avatar
5 votes
Accepted

How to immediately redirect to an entry after creating the new entry from a frontend form?

I think the answer is as simple as providing the new Entry's URI to the redirectInput function: <form method="POST"> {{ actionInput('entries/save-entry') }} {{ redirectInput('{uri}'...
August Miller's user avatar
4 votes

How to save a new entry with custom fields - Craft 3

It turns out the data wasn't being saved as I hadn't set a fieldLayoutId value. Now that I've figured this out, I've written a helper method to make saving any entry type much easier: public static ...
SteveEdson's user avatar
4 votes

Update form entry using the Guest Entries plugin

I've figured it out Go to GuestEntriesController.php and add this line of code on the 182nd line $entry->id = craft()->request->getPost('entryId'); Then add an hidden input field with the ...
Branko's user avatar
  • 497
4 votes

How can I set a Neo field's values from my plugin/module?

I just figured it out. For anyone facing the same issue, here is what worked for me: $entryData = self::setupEntryData($item); $entry = new Entry($entryData); $fieldValues = [ 'blocks' => [ /...
Danail Emandiev's user avatar
4 votes

How to create a new Entry model in Craft 3?

Just so there's an answer here. OP was using Craft 2 code in a Craft 3 environment. The code should be something like this in Craft 3: $entry = new Entry(); $entry->sectionId = $yourSectionId; $...
billythekid's user avatar
3 votes
Accepted

Parent are not set anymore after saveElement()

You need to use newParentId: $navigationItem = new Entry(); $navigationItem->typeId = 4; $navigationItem->sectionId = $navigationSection->id; $navigationItem->title = $entry->title; $...
Oli's user avatar
  • 7,515
3 votes
Accepted

Can entries be disabled by default for 2/3 of the languages on my website

Is it possible to have the Japanese and English version disabled by default? Yes. Visit Settings -> Sections -> [Your Section Name] inside the Control Panel. Under the heading Which locales should ...
Mats Mikkel Rummelhoff's user avatar
3 votes
Accepted

Will having the Craft storage directory (CRAFT_STORAGE_PATH) on a Digital Ocean Volume (like AWS EBS) dramatically affect CMS save performance?

Even if a request (or specifically an Element save operation) doesn't make much use of a file-based cache, it will likely compile and read templates from the storage directory. Logs will also be ...
August Miller's user avatar
2 votes
Accepted

How to submit custom fields that are added in the right pane to your plugin?

I think I found the answer, correct me if I'm wrong but you can access your post data in your plugin with: craft()->request->getPost('fields') Not sure if this is the recommended way.
Thaoms's user avatar
  • 93
2 votes
Accepted

Entry should not activated by default

You can change the default entry status in your section settings. Example: If I would set the German toggle to disabled, all entries added to German local will be disabled by default.
Tom De Smet's user avatar
  • 1,456
2 votes
Accepted

Built in validate of title when using EntryModel?

You could hook into the entries.beforeSaveEntry event like this: craft()->on('entries.beforeSaveEntry', function (Event $e) { // Get the entry we're saving, and it's title $entry = $e->...
Mats Mikkel Rummelhoff's user avatar
2 votes
Accepted

Single type for entry submission on error loses entry object

From the README: If there is a validation error on the entry, then the page will be reloaded with an entry variable available to it... You can override the variable name by setting the ...
Stephen Lewis's user avatar
2 votes
Accepted

How to save multiple related entries on the frontend with 1 checkbox?

You can't solve that with one input alone but you can make use of hidden fields (like craft does) Your solution would be 1 visible dummy checkbox and multiple hidden "real" inputs.. So your visible ...
Robin Schambach's user avatar
2 votes

Radio buttons in matrix field not saving

Steps to fix: Change the radio button default to an alternative option. Go to entry and remove the matrix block. Save entry Readd the matrix block. You should be able to correctly save the block, a ...
sput's user avatar
  • 31
2 votes
Accepted

Update a lightswitch field in Craft CMS 2

If it's only one single field and you want to bypass all Craft validations for required fields you can change the value directly in your database using Yii commands and the update function function ...
Robin Schambach's user avatar
2 votes
Accepted

How to save an entry using AJAX on a frontend Form [ for registered users]

As per the comments, the issue turned out to be that jQuery wasn't included on the page, so $ wasn't defined. In general, make sure to check the devtools console for error messages and use the ...
MoritzLost's user avatar
  • 11.9k
1 vote

Change matrixblock field value before save element

After a bit of testing, it appears you don't have anything to do to have your values saved, just set them and Craft will take care of the rest. Event::on( Elements::class, Elements:...
nstCactus's user avatar
  • 1,149
1 vote

Update entry Enabled value based on field value when saving

Looking into this more and understanding how Craft works, a post date needed to be set, it will not do this automatically for you. On saving the entry, it will check to see if the entry is enabled ...
zizther's user avatar
  • 449
1 vote

How to create a new Entry model in Craft 3?

You can download and see guest-entries plugin code to correctly see how to save an entry from a plugin.
jamesSeb's user avatar
1 vote

How to create a new Entry model in Craft 3?

Either use use craft\elements\Entry; $entry = new Entry(); OR $entry = new \craft\elements\Entry();
jamesSeb's user avatar
1 vote
Accepted

Redirect after saving an entry

The redirect url always needs to be hashed: https://docs.craftcms.com/v3/dev/functions.html#redirectinput In Twig you can use {{ redirectInput(url) }} which is a shortcut of <input type="hidden" ...
terdelyi's user avatar
1 vote
Accepted

Posting children to a Structure

The section ID was incorrect - set correctly and this function works.
Graham Winston's user avatar
1 vote

Entry not saving when Redactor bold

Looks like this was a ModSecurity tripping up the contents of the particular Redactor field in the POST request. The nuclear option for a fix is to disable ModSecurity. The more nuanced fix is to ...
Brad Bell's user avatar
  • 67.6k
1 vote

Allow registered end-user to update entry, but limited only to specific fields (Craft 3)

You can include a custom Behavior like the ContentBehavior/ FieldLayoutBehavior in Craft 3 and handle those by yourself. This way you'll be able to handle permissions by yourself. There are certain ...
Robin Schambach's user avatar
1 vote

How do I change the value of a select box field of a certain entry through the front-end?

Twig You can check for certain URL parameters via {% set param = craft.app.getRequest().getParam('id') %} {% if param is not null %} {% set entry = craft.app.getElements().getElementById(param) %} ...
Robin Schambach's user avatar
1 vote

Craft entries won't save (new or edits)

The issue for me here was mod_security. Once that was adjusted w/ the host, all was well again.
Danielle LeComte's user avatar
1 vote

Craft entries won't save (new or edits)

For anyone experiencing this issue, what solved it for me was deleting the craft application files and replacing them with the ones from the same release version. It seems one of them got corrupted ...
stojda's user avatar
  • 163

Only top scored, non community-wiki answers of a minimum length are eligible