getgrav / getgrav/grav-plugin-form
issue with checkbox | switch and complex blueprints
- Dominant language
- PHP
- Stars
- 64
- Forks
- 80
- Avg merge
- 10h 13m
- Merged PRs (30d)
- 9
Description
Form.php
from line 658:
> foreach ($this->items['fields'] as $key => $field) {
> $name = isset($field['name']) ? $field['name'] : $key;
> if (!isset($field['name'])) {
> if (isset($data[$i])) { //Handle input@ false fields
> $data[$name] = $data[$i];
> unset($data[$i]);
> }
> }
> if ($field['type'] === 'checkbox' || $field['type'] === 'switch') {
> $data[$name] = isset($data[$name]) ? true : false;
> }
> $i++;
> }
this code will not work with a blueprint where fields are wrapped in columns or other structures, i.e.:
```
form:
name: contatto
fields:
columns:
type: columns
classes: g-grid
fields:
column1:
type: column
classes: size-50
fields:
-
name: nome
display_label: false
placeholder: Nome
autocomplete: 'on'
type: text
validate:
required: true
column2:
type: column
classes: size-50
fields:
-
name: cognome
display_label: false
placeholder: Cognome
autocomplete: 'on'
type: text
validate:
required: true
column3:
type: column
classes: size-50
fields:
-
name: email
display_label: false
placeholder: 'Indirizzo E-Mail'
type: email
validate:
required: true
column4:
type: column
classes: size-50
fields:
-
name: telefono
display_label: false
placeholder: Telefono
type: text
column5:
type: column
classes: size-100
fields:
-
name: messaggio
display_label: false
placeholder: Messaggio
type: textarea
rows: 5
validate:
required: true
-
name: privacy
type: checkbox
label: "Acconsento al trattamento dei dati ai sensi dell’art. 23 D.Lgs. 30 giugno 2003, n. 196 “Codice in materia di protezione dei dati personali” secondo l'informativa sulla privacy linkata in calce al sito"
validate:
required: true
-
name: g-recaptcha-response
outerclasses: captcha
display_label: false
type: captcha
recaptcha_not_validated: 'Controllo antispam non superato!'
validate:
required: true
```
The checkbox never validates because `if ($field['type'] === 'checkbox' || $field['type'] === 'switch') {` will not be executed
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in Form.php around line 658 and trace how fields are iterated when a blueprint wraps them in columns or other structures. Reproduce the example with its privacy checkbox and verify that checkbox and switch fields inside nested structures reach the validation handling. Done means the checkbox validates correctly in this blueprint shape.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100