Avoid PHP 8 warnings on newsletter submissions without an action - #131
Merged
kpodemski merged 2 commits intoJul 2, 2026
Merged
Conversation
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.
|
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! |
Removed comments explaining action retrieval for PHP 8 compatibility.
kpodemski
approved these changes
Jul 2, 2026
|
PR merged, well done! Message to @PrestaShop/committers: do not forget to milestone it before the merge. |
Contributor
|
thanks @boo-code 👍🏻 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 carryingsubmitNewsletterand a valid email but noactionfield — common from bots and partial/misconfigured form posts — therefore raisedUndefined array key "action"warnings on PHP 8 on every such request. The fix reads the value once withTools::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()returnsfalse, andfalse == self::NEWSLETTER_SUBSCRIPTION (0)).actionfield (curl -X POST -d 'submitNewsletter=1&email=test@example.com' https://<shop>/) and check the PHP error log. Before: fourUndefined array key "action"warnings; after: none. Verified by invokingnewsletterRegistration()withsubmitNewsletter+ a valid email and noaction: 4 warnings before, 0 after, and the email is still subscribed (behaviour preserved).Root cause reported by @seederp2p.