0

I have a dynamic form that creates entries in Craft 3 Pro. These entries are displayed in a "Profile Page" for each user, but it only shows the newly created entries after hitting refresh 2 or 3 times. This is the code I use to fetch them:

Craft entries loop

{% extends "layout" %}

{% block content %}

    {% set entries = craft.entries.section('cotizaciones').authorId(currentUser.id).orderBy('dateCreated desc').search('statusDeCotizacion:recibido OR statusDeCotizacion:enProceso').limit(null) %}
    {% set countEntries = craft.entries.section('cotizaciones').authorId(currentUser.id).orderBy('dateCreated desc').search('statusDeCotizacion:recibido OR statusDeCotizacion:enProceso').count() %}

    {% if countEntries > 0 %}
        {% for entry in entries %}
            {% include "..." with {'active': true} %}
        {% endfor %}
    {% else %}
        NO ENTRIES
    {% endif %}

{% endblock%}

I've run some tests on Incognito and it seems to work a lot better, is there a default cache that I can bypass to make this process more seamless?

EDIT: jQuery form code

$('.entry__form').submit(function(ev) {
    ev.preventDefault();
    var entryData = $(this).serialize();
    ...

    $.post({
        url: '/',
        dataType: 'json',
        data: entryData,
        success: function(response) {
            if (response.success) {
                console.log("Entry success");
            }
        }
    });
});

This does console out "Entry success" and adds the entry to the database.

  • 1
    Can you add the code for the form? – Oli Jul 14 at 9:33
  • @Oli Done, it's a simple (and successful) Ajax call. – brunouno Jul 14 at 13:32
  • Do you set enabled on the entry you are saving? – Oli Jul 14 at 14:02
  • Yup. Everything works after a couple of browser refreshes which is what I find odd. – brunouno Jul 14 at 14:20
  • And are you posting to Craft's entries/save-entry or a custom controller action? – Oli Jul 14 at 14:23

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.