Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR #11293 causes documented blade solution for forms to not work. #11369

Closed
tom-oneshotdigital opened this issue Jan 17, 2025 · 4 comments · Fixed by #11374
Closed

PR #11293 causes documented blade solution for forms to not work. #11369

tom-oneshotdigital opened this issue Jan 17, 2025 · 4 comments · Fixed by #11374

Comments

@tom-oneshotdigital
Copy link

Bug description

After upgrading to version 1.54.0 which included pull request 11293([5.x] Allow form fields view to be rendered with single tag) all of my forms stopped being able to render.

In my case I have followed the Blade version of the documentation from "The Template" which states you have to @foreach over the fields. However the change in this PR changes the result from an array of the form inputs to the FieldsVariable object.

My fix from the documented

// Loop through and render the form inputs
@foreach ($fields as $field)
  <div class="p-2">
    <label>{{ $field['display'] }}</label>
    <div class="p-1">{!! $field['field'] !!}</div>
    @if ($field['error'])
      <p class="text-gray-500">{{ $field['error'] }}</p>
    @endif
  </div>
@endforeach

was to call toArray() on the $fields object

// Loop through and render the form inputs
@foreach ($fields->toArray() as $field)
  <div class="p-2">
    <label>{{ $field['display'] }}</label>
    <div class="p-1">{!! $field['field'] !!}</div>
    @if ($field['error'])
      <p class="text-gray-500">{{ $field['error'] }}</p>
    @endif
  </div>
@endforeach

I feel like $fields->toArray() should just be a workaround as the documented version makes more sense from a Blade point of view.

How to reproduce

Create a form in the control panel, follow the documented solution to render the form using blade templates, $fields are not rendered because they are no longer an array.

Logs

Environment

Environment
Laravel Version: 11.38.2
PHP Version: 8.3.8
Composer Version: 2.5.1
Environment: local
Debug Mode: ENABLED
Maintenance Mode: OFF
Timezone: UTC
Locale: en

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

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

Livewire
Livewire: v3.5.18

Statamic
Addons: 7
Sites: 1
Stache Watcher: Enabled
Static Caching: Disabled
Version: 5.45.1 PRO

Statamic Addons
aerni/font-awesome: 3.0.2
alt-design/alt-cookies: 1.1.7
alt-design/alt-seo: 1.2.2
alt-design/alt-sitemap: 1.2.3
daun/statamic-widget-collection-count: 1.3.1
jonassiewertsen/statamic-livewire: 3.8.1
statamic-rad-pack/mailchimp: 5.2.2

Installation

Fresh statamic/statamic site via CLI

Additional details

No response

@martyf
Copy link
Contributor

martyf commented Jan 20, 2025

This is an issue outside of templating too.

I have been getting $fields from the context within a tag, but it now returns the new FieldsVariable instead, so I need to now check if it is that type, and if so, call extra() to get the original array.

While it is more of an edge case, this is a breaking change to existing behaviours.

@wiljanslofstra
Copy link

I had the same issue in Antlers. Downgraded to version 5.44.0 and it works again.

My code looks a bit like this:

{{ form:my_form_name }}
    {{ partial:components/form-render }}
{{ /form:my_form_name }}

form-render.antlers.html:

{{ fields scope="field" }}
  {{ field:display }}
{{ /fields }}

Exception:

Illuminate\Support\Arr::isAssoc(): Argument #1 ($array) must be of type array, Statamic\Forms\FieldsVariable given, called in /home/forge/my-project-name/releases/65/vendor/statamic/cms/src/Support/Arr.php on line 323

@stuartcusackie
Copy link

Noticed the same trouble today. I use the old Statamic:tag method, e.g. $form = Statamic::tag("form:{$handle}")

Adding toArray() fixes it, i.e.:
@foreach($form['fields']->toArray() as $field)

@duncanmcclean
Copy link
Member

Just tagged v5.45.2 which reverts the PR causing the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants