0

I'm using this answer along with the Guest Entries plugin to allow guest users to edit entries via a frontend form.

It was working beautifully before, and after updating Craft it's now taking ages and freezing the entire site before it completes several minutes later.

Any idea what could be going on?

Module.php

Event::on(
        SaveController::class,
        SaveController::EVENT_BEFORE_SAVE_ENTRY,
        function(SaveEvent $event) {
            $request = Craft::$app->getRequest();

            // Get the entry being edited
            $entryId = $request->getBodyParam('entryId');
            $currentEntry = Entry::find()->id($entryId)->anyStatus()->one();

            if (!$currentEntry) {
                throw new BadRequestHttpException('Invalid entry ID: ' . $entryId);
            }

            // Populate the guest submission with the entry ID, UID, and content ID
            $event->entry->id = $currentEntry->id;
            $event->entry->uid = $currentEntry->uid;
            $event->entry->contentId = $currentEntry->contentId;
        }
    );

form.twig

{% set slug = craft.app.request.getSegment(2) %}
{% if entry is not defined %}
    {% set entry = craft.entries.section('releases').slug(slug).status('disabled').one() %}
{% endif %}
{% if not entry|length %}
    {% redirect 'form-error' %}
{% endif %}

<div class="container rounded my-3">
    <div class="row">
        <div class="col p-4 px-5">

            <header>
                <h1 class="text-center">
                    <img width="150" src="/assets/images/header-logo.png"/>
                </h1>
                <h2 class="text-center mt-3">Featured Release Submission Form</h2>
            </header>
            <hr/>

            <div class="form mt-3">

                {% if entry.hasErrors() %}
                    <div class="alert alert-danger mb-4" role="alert">
                        Please check your entry and fix the errors below.
                        {% set allErrors = entry.getErrors() %}
                        {% for error in allErrors %}
                            {{ error[0] }}
                        {% endfor %}
                    </div>
                {% elseif craft.app.request.getQueryParam('success') %}
                    <div class="alert alert-success mb-4" role="alert">
                        Your submission has been saved successfully. Please check and update if needed.
                    </div>
                {% endif %}

                {% if entry.artist.one().title is defined %}
                    <h4 class="mb-4">{{ entry.artist.one().title ?? entry.artist.one().title|raw }}
                        - {{ entry.title|raw }}</h4>
                {% endif %}

                {% macro errorList(errors) %}
                    {% if errors %}
                        {{ ul(errors, {class: 'errors'}) }}
                    {% endif %}
                {% endmacro %}

                {% from _self import errorList %}

                {# Add `enctype="multipart/form-data"` to `<form>` if you’re #}
                {# uploading files. #}
                <form method="post" accept-charset="UTF-8" enctype="multipart/form-data">
                    {{ csrfInput() }}
                    {{ actionInput('guest-entries/save') }}
                    {{ redirectInput('form/{slug}?success=true') }}
                    {{ hiddenInput('sectionUid', '3b2cccdf-e40b-48a5-aed9-c364e55a6051') }}
                    {{ hiddenInput('entryId', entry.id) }}
                    {{ hiddenInput('title', entry.title) }}
                    {{ hiddenInput('slug', entry.slug) }}
                    {{ hiddenInput('enabled', '0') }}
                    {{ hiddenInput('fields[paidPromotion]', 'none') }}

                    {% set tz = craft.app.getTimezone() %}
                    {% set df = 'yy-m-d' %}

                    <div class="form-group {{ entry.getErrors('releaseDate')|length ? 'error' : '' }}">
                        <label for="releaseDate" class="mb-2">Release Date</label>
                        {{ input('date', 'fields[releaseDate][date]', entry.releaseDate is defined ? entry.releaseDate|date(df, tz) : '', {
                            id: 'releaseDate',
                            class: 'datechk form-control',
                        }) }}
                        {{ hiddenInput('fields[releaseDate][timezone]', tz) }}
                        {{ _self.errorList(entry.getErrors('releaseDate')) }}
                    </div>

                    <div class="form-group {{ entry.getErrors('artwork')|length ? 'error' : '' }}">
                        <label for="artwork" class="mb-2">Artwork</label>
                        {% if entry.artwork.one().url is defined %}
                            <img src="{{ entry.artwork.one().url }}?v={{ now.timestamp }}"
                                 alt="{{ entry.artwork.one().title|raw }}" width="100" height="100">
                        {% endif %}
                        <small id="artworkHelp" class="form-text text-muted">High resolution .jpg file, at least 1500 x
                            1500 pixels. 10MB maximum filesize.</small>
                        {{ input('file', 'fields[artwork]', entry.artwork.id, {
                            id: 'artwork',
                            class: 'form-control',
                        }) }}
                        {{ _self.errorList(entry.getErrors('artwork')) }}
                    </div>

Your Answer

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

Browse other questions tagged or ask your own question.