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', [$...
user avatar
  • 6,226
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 ...
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\...
user avatar
5 votes
Accepted

Entry validation not working when Publish live changes permission is not checked

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 ...
user avatar
4 votes

Entry validation not working when Publish live changes permission is not checked

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 ...
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 ...
user avatar
  • 485
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 ...
user avatar
4 votes
Accepted

Entry slug auto appends -1 even when the original slug is unique

I don't know the specific rules Craft uses but I believe Craft auto appends the -1 when it tries to save an Element that has a matching URI in the craft_elements_i18n table. A few scenarios that I ...
user avatar
  • 13.2k
4 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}'...
user avatar
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 ...
user avatar
3 votes
Accepted

Can't rename slug

You can connect to your database and run: SELECT * FROM craft_elements_i18n WHERE slug = 'forms'; to see what other element is already using the slug forms. To see what type of element it is (Entry,...
user avatar
  • 66.4k
3 votes

Entry validation not working when Publish live changes permission is not checked

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!
user avatar
  • 35.8k
3 votes
Accepted

How to use select dropdown with entries/saveEntry for an entry field?

I ran into this a while ago and it drove me nuts. Try adding disabled and selected attributes to your initial option in the select. So in your case <option disabled selected>---</option>.
user avatar
3 votes
Accepted

saveEntry() not firing

Something on the $entryToSave EntryModel is failing validation. If you echo out implode(', ', $entryToSave()->getAllErrors());, then you'll see what those errors are and you can correct them.
user avatar
  • 66.4k
3 votes
Accepted

onBeforeSaveEntry is hanging on import

Your script probably chokes because you're interacting with an undeclared variable $params – i.e. change if($params['isNewEntry']) { to if($event->params['isNewEntry']) {
user avatar
3 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; $...
user avatar
3 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' => [ /...
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; $...
user avatar
  • 7,160
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 ...
user avatar
2 votes

Assign entry id to title with entry form

That would be the same behavior for using {id} in the title format for new entries created in the control panel as well. The problem with {id} is that's not known until the entry is already saved to ...
user avatar
  • 66.4k
2 votes
Accepted

Craft\EntryModel and its behaviors do not have a method or closure named "ui"

My mistake... I had {parent.ui} as the nested entry slug for the section. {parent.uri} is correct.
user avatar
2 votes
Accepted

<form><matrixBlock><checkbox></matrixBlock></form> How do I store multiple form entries in 1 table field?

You can't just append rows to an existing table field from a form. The controller expects the complete data set, so you'd need to query for the existing rows in your template and post them together ...
user avatar
  • 35.8k
2 votes

Checking for first time an entry is "published" i.e. saved with a Live status

There isn't an "event" that gets fired when an entry goes live, but you should be able to listen to the onSaveEntry event, then check the same criteria that Craft uses to determine if an entry is live ...
user avatar
  • 66.4k
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.
user avatar
  • 83
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.
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->...
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 ...
user avatar
2 votes

Craft\Exception on saving entries having images

I'm going to go out on a limb and say you're trying to upload a file type that isn't allowed under that Asset fields "Restrict Allowed File Types?" section.
user avatar
  • 66.4k
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 ...
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 ...
user avatar
  • 31

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