Skip to content

Commit 0b73d81

Browse files
committed
fix: handle missing active field and cast sticky to bool on FAQ create, closes #4329
When answering an open question, the FAQ editor renders with neither active radio checked, so FormData omits `active`. Also the sticky checkbox posts "on", but FaqEntity::setSticky() requires bool.
1 parent cb49656 commit 0b73d81

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

phpmyfaq/src/phpMyFAQ/Controller/Administration/Api/FaqController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function create(Request $request): JsonResponse
101101

102102
$language = Filter::filterVar($data->lang, FILTER_SANITIZE_SPECIAL_CHARS);
103103
$tags = Filter::filterVar($data->tags, FILTER_SANITIZE_SPECIAL_CHARS);
104-
$active = Filter::filterVar($data->active, FILTER_SANITIZE_SPECIAL_CHARS);
104+
$active = Filter::filterVar($data->active ?? 'no', FILTER_SANITIZE_SPECIAL_CHARS);
105105
$sticky = Filter::filterVar($data->sticky ?? 'no', FILTER_SANITIZE_SPECIAL_CHARS);
106106
$content = Filter::filterVar($data->answer, FILTER_SANITIZE_SPECIAL_CHARS);
107107
$keywords = Filter::filterVar($data->keywords, FILTER_SANITIZE_SPECIAL_CHARS);
@@ -127,7 +127,7 @@ public function create(Request $request): JsonResponse
127127
$faqData
128128
->setLanguage($language)
129129
->setActive($active === 'yes')
130-
->setSticky($sticky !== 'no' ? $sticky : false)
130+
->setSticky($sticky !== 'no')
131131
->setQuestion(Filter::removeAttributes(html_entity_decode(
132132
(string) $question,
133133
ENT_QUOTES | ENT_HTML5,
@@ -311,7 +311,7 @@ public function update(Request $request): JsonResponse
311311

312312
$faqLang = Filter::filterVar($data->lang, FILTER_SANITIZE_SPECIAL_CHARS);
313313
$tags = Filter::filterVar($data->tags, FILTER_SANITIZE_SPECIAL_CHARS);
314-
$active = Filter::filterVar($data->active, FILTER_SANITIZE_SPECIAL_CHARS);
314+
$active = Filter::filterVar($data->active ?? 'no', FILTER_SANITIZE_SPECIAL_CHARS);
315315
$sticky = Filter::filterVar($data->sticky ?? 'no', FILTER_SANITIZE_SPECIAL_CHARS);
316316
$content = Filter::filterVar($data->answer, FILTER_SANITIZE_SPECIAL_CHARS);
317317
$keywords = Filter::filterVar($data->keywords, FILTER_SANITIZE_SPECIAL_CHARS);

0 commit comments

Comments
 (0)