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', [$...
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 ...
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\...
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 ...
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 ...
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 ...
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 ...
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 ...
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}'...
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 ...
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,...
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!
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>.
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.
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']) {
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;
$...
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' => [ /...
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;
$...
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 ...
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 ...
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.
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 ...
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 ...
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.
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.
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->...
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 ...
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.
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
saveentry × 53entry × 10
entries × 8
plugin-development × 7
craft3 × 5
form × 5
frontend × 5
matrix × 4
onsaveentry × 4
events × 3
controller × 3
control-panel × 2
redactor × 2
structure × 2
ajax × 2
redirect × 2
modules × 2
validation × 2
slug × 2
frontend-form × 2
entrymodel × 2
services × 2
editor × 2
plugin-guestentries × 2
entry-form × 2