cms icon indicating copy to clipboard operation
cms copied to clipboard

Hidden fields don't show in the form submission

Open aerni opened this issue 1 year ago • 4 comments

Bug description

Fields that have visibility: hidden don't show up in the form submission view. I'm expecting all fields to show and be read_only in the form submission view, regardless of their visibility setting. Currently, fields are only visible when they have either visibility: visible or visibility: read_only.

How to reproduce

  1. Create a form
  2. Add three fields, each with a different visibility setting
  3. Create a form submission
  4. Recognize that the field with visibility: hidden is not showing in the CP

Logs

No response

Environment

Environment
Application Name: TDS Aarau
Laravel Version: 9.22.0
PHP Version: 8.1.6
Composer Version: 2.3.5
Environment: local
Debug Mode: ENABLED
URL: tdsaarau.test
Maintenance Mode: OFF

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

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

Statamic
Addons: 8
Antlers: runtime
Version: 3.3.23 PRO

Statamic Addons
aerni/livewire-forms: 6.0.0
aryehraber/statamic-impersonator: 2.4.1
doublethreedigital/duplicator: 2.3.1
jacksleight/statamic-bard-mutator: 1.1.1
jacksleight/statamic-bard-texstyle: 1.0.3
jonassiewertsen/statamic-livewire: 2.9.0
spatie/statamic-responsive-images: 2.13.0
visuellverstehen/statamic-classify: 2.4.0

Installation

Fresh statamic/statamic site via CLI

Antlers Parser

runtime (new)

Additional details

This is also true for the Hidden fieldtype. I'm also expecting this field to be visible in the form submission.

aerni avatar Jul 28 '22 17:07 aerni

Oh interesting. Could we get more info on your use case?

jesseleite avatar Jul 28 '22 17:07 jesseleite

I'll whip up a repo.

aerni avatar Jul 28 '22 18:07 aerni

Here you go: https://github.com/aerni/hidden-form-fields.

Just create a super user and navigate to the contact form.

All fields are visible in the submission listing view:

Bildschirmfoto 2022-07-28 um 14 43 32

But not all of them are visible in the individual submission view:

Bildschirmfoto 2022-07-28 um 14 43 45

aerni avatar Jul 28 '22 18:07 aerni

My use case

I've got an event sign-up form. To identify which event a user signed up for, I'm passing the event ID as a hidden form input. The CP user should be able to see all submitted data, no matter the visibility of the field on the frontend. I'm using my Livewire Forms addon. The addon picks up the visibility state of the field to determine if a field should be hidden on the frontend. Same goes for the Hidden fieldtype.

aerni avatar Jul 28 '22 18:07 aerni

I have a similar use case as above, but wanted to add that if you have the field as Visible but change the html5 Input Type to 'hidden' it results in a similar issue with just the field label showing and the input field not. I would expect the submission detail to show the field even though its input type is 'hidden' (which would be for the front end form output).

micahhenshaw avatar Mar 30 '23 01:03 micahhenshaw

If you give a field a visibility of hidden, it should be hidden in the CP. That's the point of it. Seems like it's working correctly to me.

There may be a disconnect with the use case in frontend forms though. Need a way to make a field hidden in the frontend but not in the cp.

Your repo doesn't show how you're using the form and fields on the front end though, unless I'm missing something.

jasonvarga avatar Mar 30 '23 16:03 jasonvarga

My use case is we have a a collection of events, and on each event detail page is a registration form, we have a hidden field (hidden by selecting the 'hidden' html5 input type): image which is populated with the event date from the collection entry so that when a registration form is submitted it also includes the date that the end user has registered on.

But in the submission detail in the CP the event date label shows but the field and value dont: image

I would have thought that the input type should ONLY apply to front end, which would leave the Visibility field to control the CP side. Currently there is no way to create a hidden field on the frontend, while maintaining the ability to see it in the submission.

micahhenshaw avatar Mar 31 '23 00:03 micahhenshaw

I'm more talking about Michael's situation.

In your case, I'm honestly not even sure why a hidden input type even exists. 😊 Selecting the "input type" makes sense for all types except hidden.

jasonvarga avatar Mar 31 '23 13:03 jasonvarga

Okay looking back at the git history, we added the option to set the input type to hidden literally for forms on the frontend. Maybe that was merged a little hastily, because while it makes sense on the frontend, once you go back to the CP to view the submission, it would also be hidden. #2952

jasonvarga avatar Mar 31 '23 14:03 jasonvarga

After some internal discussion, we're thinking of possibly removing input_type: hidden on the text field altogether, since it's an input type that was only added for frontend forms, but obviously confusing and broken in the submission view.

For the use cases mentioned above, if you use input_type: text it'll be visible in the form submission in the CP, and you can still control visibility/rendering in your html markup...

{{ form:contact }}

    {{ fields }}
        {{ if handle == "event_name" }}
            <input name="event_name" type="hidden" value="{{ event_name }}">
        {{ elseif handle == "event_date" }}
            <input name="event_date" type="hidden" value="{{ event_date }}">
        {{ else }}
            <label>{{ display }}</label>
            <div class="p-1">{{ field }}</div>
        {{ /if }}
    {{ /fields }}

    <button>Submit</button>

{{ /form:contact }}

jesseleite avatar Mar 31 '23 16:03 jesseleite

There may be a disconnect with the use case in frontend forms though. Need a way to make a field hidden in the frontend but not in the cp.

Yes, you're right. Visibility is working as expected but doesn't make much sense for form submissions. I'm probably "abusing" the visibility to build my frontend forms.

Your repo doesn't show how you're using the form and fields on the front end though, unless I'm missing something.

I didn't add this as I'm using my Livewire Forms addon. I'm basically using the visibility of a field to hide input fields. That's it.

I generally think that the main issue with fieldtypes in the form builder is the disconnect between CP and frontend. Like the duplicate and mode options of the asset fieldtype. They don't make much sense in the context of forms.

Anyhow, I think the easy solution for my problem would be to simply show fields with visibility hidden in the form submissions. Or else remove the visibility options for forms to not confuse the users. (Except if you're still thinking about adding computed fields to forms at some point, like mentioned over here: https://github.com/statamic/ideas/issues/834.)

aerni avatar Apr 04 '23 09:04 aerni