Fields in forms
Forms render fields with the same code as the edit screens
(Cybo\AdvancedFieldEngine\Admin\FieldRenderer) and save them with the same service as
cafe_update_field() (Cybo\AdvancedFieldEngine\API\FieldService). A field type that works on an
edit screen works in a form; there is no separate list of "form field types".
What the form shows
- Every top-level field of the chosen field groups, in the group's order.
- Tabs, Collapsible Sections and Messages of those groups (they hold no value).
- Extra fields given one by one with
fields(by key or name). - Minus media fields for people who may not upload (see Media).
- Minus fields removed with
cafe_dynamic_form_fields: removed fields are also refused when submitted. - Fields an integration hides (
cafe_field_viewstatehidden) are not shown; read-only ones are shown locked and never saved.
Field types
| Kind | Types | Notes |
|---|---|---|
| Text | Text, Textarea, Email, URL, Password, Number, Range | Password values are never printed; empty = keep. |
| Rich text | Rich Text Editor | Uses the WordPress editor (TinyMCE) on the page. The text is sent when the form is sent. |
| Choice | Select, Checkbox, Radio, Button Group, Toggle | Values must be one of the choices. |
| Date & time | Date, Date Time, Time | |
| Color | Color | |
| Media | Image, File, Gallery, Video | Only for people with upload_files; see Media. |
| References | Post Object, Page Link, Relationship, Taxonomy, User | Searched through the form's own endpoint; see Relationships. |
| Link, oEmbed, Google Map | Link, oEmbed, Google Map | Google Map needs its API key on the front end too. |
| Layout | Tab, Collapsible Section, Message, Field Set, Collection, Section Builder, Clone | See Collections and Layout. |
All of these go through the same path: render → submit → field validation →
cafe_dynamic_form_validate → save → shown again on the next load. The test
suite (tests/Integration/DynamicFormsTest.php) submits text, number,
password, image, relationship, collection and taxonomy values through forms;
the other types share the exact same code path as those edit-screen tests.
Custom field types
A field type registered with cafe_register_field_type()
works in forms without changes: its render_input() draws the input and its
validation and sanitization run on submit. If it needs JavaScript, enqueue it
on wp_enqueue_scripts as well as on edit screens.
Defaults and saved values
Create forms show each field's Default Value. Edit forms show the saved values. After a failed submit without JavaScript, top-level fields show what was typed; items inside Collections show the saved state (with AJAX, nothing is reloaded, so everything typed stays).