Skip to content

Avoid PHP 8 warnings on newsletter submissions without an action - #131

Merged
kpodemski merged 2 commits into
PrestaShop:devfrom
boo-code:fix/newsletter-action-php8-warning-125
Jul 2, 2026
Merged

kpodemski merged 2 commits into
PrestaShop:devfrom
boo-code:fix/newsletter-action-php8-warning-125

Conversation

@boo-code

Copy link
Copy Markdown
Contributor
Questions Answers
Description? Ps_Emailsubscription::newsletterRegistration() read $_POST['action'] in four places without checking it exists (the Before/After hook payloads and the two subscribe/unsubscribe branches). A POST carrying submitNewsletter and a valid email but no action field — common from bots and partial/misconfigured form posts — therefore raised Undefined array key "action" warnings on PHP 8 on every such request. The fix reads the value once with Tools::getValue('action') and reuses it. Behaviour is unchanged: a missing action does not equal the unsubscription value and is handled as a subscription, exactly as before (Tools::getValue() returns false, and false == self::NEWSLETTER_SUBSCRIPTION (0)).
Type? bug fix
BC breaks? no
Deprecations? no
Fixed ticket? Fixes #125.
How to test? On PHP 8.1+, POST a newsletter submission without an action field (curl -X POST -d 'submitNewsletter=1&email=test@example.com' https://<shop>/) and check the PHP error log. Before: four Undefined array key "action" warnings; after: none. Verified by invoking newsletterRegistration() with submitNewsletter + a valid email and no action: 4 warnings before, 0 after, and the email is still subscribed (behaviour preserved).
Sponsor company

Root cause reported by @seederp2p.

newsletterRegistration() read $_POST['action'] in four places without a guard,
so a submission carrying submitNewsletter and a valid email but no action field
(bots, partial form posts) raised "Undefined array key \"action\"" warnings on
PHP 8. Read it once with Tools::getValue('action') and reuse it. A missing action
keeps its previous meaning - it does not equal the unsubscription value and is
handled as a subscription, exactly like before.
@ps-jarvis

Copy link
Copy Markdown

Hello @boo-code!

This is your first pull request on ps_emailsubscription repository of the PrestaShop project.

Thank you, and welcome to this Open Source community!

@github-project-automation github-project-automation Bot moved this to Ready for review in PR Dashboard Jun 27, 2026
Removed comments explaining action retrieval for PHP 8 compatibility.
@kpodemski
kpodemski merged commit 5965a7a into PrestaShop:dev Jul 2, 2026
12 checks passed
@github-project-automation github-project-automation Bot moved this from Ready for review to Merged in PR Dashboard Jul 2, 2026
@ps-jarvis ps-jarvis moved this from Merged to To be tested in PR Dashboard Jul 2, 2026
@ps-jarvis ps-jarvis moved this from To be tested to Merged in PR Dashboard Jul 2, 2026
@ps-jarvis

Copy link
Copy Markdown

PR merged, well done!

Message to @PrestaShop/committers: do not forget to milestone it before the merge.

@kpodemski kpodemski added this to the 2.8.4 milestone Jul 2, 2026
@kpodemski

Copy link
Copy Markdown
Contributor

thanks @boo-code 👍🏻

@kpodemski kpodemski added QA ✔️ Status: Check done, Code approved QA ✔️ by Community Status: Check done by community member, Code approved and removed Waiting for QA labels Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

QA ✔️ by Community Status: Check done by community member, Code approved QA ✔️ Status: Check done, Code approved

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Undefined array key "action" warnings in newsletterRegistration() on PHP 8

3 participants