Open mikemartin opened 8 years ago
What is this for, exactly?
@jackmcdade
This would give CP admins the ability to create any type of Form they need with the form builder. I already have this running on a client site, but adding the 3 fields described above had to be done by editing the formset YAML directly.
There are two additional steps to get this to work:
1) Add a Form page template where the admin can select their form. I created a form suggest field to help with this. https://github.com/lesaff/statamic2-suggestmodes#forms 2) Create the form template that loops through each field. (example above)
Ah okay I get you now. Will think about the most flexible way to support this goal.
@jackmcdade Great thanks! Here are some example forms that I've built. I've also attached their fieldsets and form template.
@jackmcdade I've been thinking about this a little more. Perhaps the most elegant solution would be if we could configure Form fields the same way we currently configure Assets fields?
This way I could add additional fields like width
, type
and instructions
myself. 👍
I would also like the front end forms to have all the flexibility and power of the forms for fieldsets and assets. This would make it a lot easier to handle changes in contact forms etc!
That's what workshop is for! 😁
No, this is for end user forms (such as a contact form, survey, application etc.), not content creation.
For example I do not want to do this as it is hacky and I would have to put in a conditional every time new fields are added to the contact form ...
{{ fields }}
<label for="{{ name }}">{{ display }}</label>
{{ if name == 'comment' }}
<textarea id="{{ name }}" for="{{ name }}">
{{ old }}
</textarea>
{{ else }}
<input id="{{ name }}" type="text" name="{{ name }}" value="{{ old }}" />
{{ /if }}
{{ /fields }}
Please let us do this instead, I think this is important to be core in Statamic forms ...
{{ fields }}
<label for="{{ name }}">{{ display }}</label>
{{ if type == 'textarea' }}
<textarea id="{{ name }}" for="{{ name }}">
{{ old }}
</textarea>
{{ else }}
<input id="{{ name }}" type="{{ type }}" name="{{ name }}" value="{{ old }}" />
{{ /if }}
{{ /fields }}
@jackmcdade thanks for reopening this. Please take a look at my example templates (contact.txt, form.txt) above if you haven't already.
This would be a great addition to the core of Statamic and would really help our clients manage and create forms and landing pages themselves.
https://github.com/statamic/v2-hub/issues/929#issuecomment-245320359
So I think Statamic even uses type now to allow asset uploads in these forms, and you can set & use the type
variable yourself in the YAML but there is no way to see this in the UI.
I think a hidden
type would be useful as well for invisible fields. My customer uses them for A/B testing and data collection.
Just had a customer request this as well. Likely going to direct them to TypeForm instead.
I've the same problem. Trying to loop over a grid where the customer can add or remove their own fields:
{{ form:create in='form' }}
{{ grid_mithilfe }}
<div class="row">
<div class="col">
<input type="checkbox" name="{{ job | slugify }}_{{ job-detail }}">
</div>
<div class="col">{{ job }}</div>
<div class="col">{{ job-detail }}</div>
<div class="col">
{{ relate:verantwortlich }}
<a href="mailto:{{ mitglied_mail }}">{{mitglied_name}}</a>
{{ /relate:verantwortlich }}</div>
</div>
{{ /grid_mithilfe }}
{{ /form:create }}
... but that doesn't work as long as the fields have to be defined in the form.yaml ...
+1 to all of this, would be very handy.
Just FYI, you can add whatever other variables you need to each field if you edit it manually through the yaml file.
Please let us do this instead, I think this is important to be core in Statamic forms ...
{{ fields }} <label for="{{ name }}">{{ display }}</label> {{ if type == 'textarea' }} <textarea id="{{ name }}" for="{{ name }}"> {{ old }} </textarea> {{ else }} <input id="{{ name }}" type="{{ type }}" name="{{ name }}" value="{{ old }}" /> {{ /if }} {{ /fields }}
Go ahead and add type: whatever
to each field. There's just no UI for it in the CP at the moment.
That's a good point, thanks.
@jasonvarga does this mean you could add in the yaml file manually stuff like
type: select
options:
- optionOne
- optionTwo
- optionThree
?
Ideally stuff like this would be editable in the CP so that clients could add options to things like contact forms, i.e. department
or how did you hear about us
+1
Please use the thumbs up emoji instead of +1ing :)
You probably have this on the roadmap but I wanted to document which fields I think would be useful for building a variety of different forms using the CP.
Fields
Type
A string to give the user flexibility to define their own fieldtypes. Here are some examples:
text
,email
,date
,number
,select
,multiple
,radio
,checkboxes
,checkbox
,textarea
Example:
Description
A string to add additional instructions or help text.
Options
A grid or array fieldtype for defining options for Select, Radio and Checkboxes.
Submit Text
Another useful field for the entire Form would be
Submit Text
. This would help users define a label for their form submit button.Use Case
With these fields available, I can then loop through fields in the same way as using the replicator. The example below assumes the user has "mounted" or added a
form
field to their page: