| @@ -8,8 +8,23 @@ | ||
| 8 | 8 | trait PredefinedForms |
| 9 | 9 | { |
| 10 | 10 | public static function resolvePredefinedForm($attributes = []) |
| 11 | 11 | { |
| 12 | + // A create request must name a template. Without this, Arr::get($map, null) | |
| 13 | + // inside findPredefinedForm() returns the WHOLE template map — a non-empty | |
| 14 | + // array that sails past both guards below and yields a form persisted with | |
| 15 | + // NULL form_fields. findPredefinedForm() itself keeps that whole-map | |
| 16 | + // behaviour on purpose: FormService::templates() depends on it. | |
| 17 | + $hasTemplateId = Arr::get($attributes, 'predefined') | |
| 18 | + || 'blank_conversational' === Arr::get($attributes, 'type'); | |
| 19 | + | |
| 20 | + if (!$hasTemplateId) { | |
| 21 | + throw new Exception( | |
| 22 | + // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Exception message, not output | |
| 23 | + __("The selected template couldn't be found.", 'fluentform') | |
| 24 | + ); | |
| 25 | + } | |
| 26 | + | |
| 12 | 27 | $predefinedForm = static::findPredefinedForm($attributes); |
| 13 | 28 | |
| 14 | 29 | if (!$predefinedForm) { |
| 15 | 30 | throw new Exception( |