juergenweb / FrontendForms

A module for ProcessWire CMS to create and validate forms on the frontend easily using the Valitron library.
MIT License
15 stars 1 forks source link

PHP Warning: Undefined array key "HTTP_USER_AGENT" #17

Open donatasben opened 1 week ago

donatasben commented 1 week ago

Hi @juergenweb, how are you? It seems I am getting a PHP warning on every page I use a from on: PHP Warning: Undefined array key "HTTP_USER_AGENT" in .../site/modules/FrontendForms/Formelements/Form.php:670 Version is 2.2.14, testing on 2.2.15 now.

juergenweb commented 1 week ago

Hello @donatasben!

This warning is weired and makes no sense to me, because the super global variable $_SERVER contains the array key "HTTP_USER_AGENT". It is a standard array key of this variable (take a look at the last line).

Screenshot 2024-09-16 at 15-48-17 Minimal Site Profile

So it is not possible that this array key does not exist. Please let me know if this warning persists. I do not know what the cause could be for this warning. There must be something going wrong.

Jürgen

donatasben commented 1 week ago

Hi @juergenweb, Yes, so I thought too that it is a standard variable and should be present always. However I think the situation is that the website is being proxied through another server that might not pass through the user agent information 🤔 I believe this might be a very rare and specific situation and not sure your module should be the place for fixing this. Probably I need to investigate into the configuration of the proxy server.

juergenweb commented 1 week ago

Hi @donatasben

I have added a check for the array key 'HTTP_USER_AGENT' on the variable '$_SERVER'. If the array key is not present, then 'n/a' will be set as the value. This string is translatable, so you can change it to your needs. This should prevent the showing up of a warning message. I do not bump up the version number after this change, but you can replace the Form.php with the latest version here on GitHub to get this fix now.

https://github.com/juergenweb/FrontendForms/blob/main/Formelements/Form.php#L655

I think it is not important to find the cause in this case, because it only needs time, but you can do it if you want.....

If this fix had solved your problem, then please close this issue.

Best regards

donatasben commented 1 week ago

Thanks a lot for the fix! Will test it out this week!