statamic / cms

The core Laravel CMS Composer package
https://statamic.com
Other
4.06k stars 530 forks source link

Form Logic (Errors / Success) doesn't work within `nocache` tags #7628

Closed sjclark closed 9 months ago

sjclark commented 1 year ago

Bug description

Success / Error form logic doesn't seem to work within nocache tags as per the docs when using full caching - the messages will not be shown.

The example is essentially just from here https://statamic.dev/tags/form-create#overview wrapped as per docs here: https://statamic.dev/tags/nocache#forms

RE: "However, if your form has logic in it, like validation or success messages, you'll need to keep the form:create dynamic by wrapping in nocache tags."

How to reproduce

Within a fresh Statamic install turn on Static Cache full Create a contact form

Try to use (from docs):

{{ nocache }}
    {{ form:create in="contact" }}
        {{ if errors }}
            <div class="bg-red-300 text-white p-2">
                {{ errors }}
                    {{ value }}<br>
                {{ /errors }}
            </div>
        {{ /if }}
        {{ if success }}
            <div class="bg-green-300 text-white p-2">
                {{ success }}
            </div>
        {{ /if }}
        <label>Email</label>
        <input type="text" name="email" value="{{ old:email }}" />

        <label>Message</label>
        <textarea name="message" rows="5">{{ old:message }}</textarea>

        <button>Submit</button>
    {{ /form:create }}
{{ /nocache }}

Attempt to use form and find that validation messages are not shown.

Logs

No response

Environment

Environment
Application Name: Statamic
Laravel Version: 9.52.4
PHP Version: 8.2.3
Composer Version: 2.2.9
Environment: local
Debug Mode: ENABLED
URL: test.test
Maintenance Mode: OFF

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: NOT CACHED

Drivers
Broadcasting: log
Cache: statamic
Database: mysql
Logs: stack / single
Mail: smtp
Queue: sync
Session: file

Statamic
Addons: 0
Antlers: runtime
Stache Watcher: Enabled
Static Caching: full
Version: 3.4.5 Solo

Installation

Fresh statamic/statamic site via CLI

Antlers Parser

runtime (new)

Additional details

It's possible that this is just an error in the docs (stating functionality that doesn't work?)

robdekort commented 1 year ago

Confirmed!

duncanmcclean commented 9 months ago

Hey 👋

I'm unable to reproduce this issue on the latest version of Statamic. The success & error messages display as expected when wrapping the form in the {{ nocache }} tag:

CleanShot 2024-01-25 at 21 17 14

I'm going to close this issue now. If you're still experiencing this issue, please leave a comment and we can re-open the issue. Thanks!