salesagility / SuiteCRM-Core

SuiteCRM - Open source CRM for the world
https://www.suitecrm.com
GNU Affero General Public License v3.0
179 stars 131 forks source link

v8.3.0 Web-to-Person form produces Error 500 on PHP 8.0.28, works fine on PHP 7.4.33 #258

Open J-Wick4 opened 1 year ago

J-Wick4 commented 1 year ago

Issue

The web-to-Person form generator's output form code does not seem to work on PHP 8.0.28 and produces an Error 500 upon form submission.

Expected Behavior

Actual Behavior

Web server log ` 954216#0: *49662 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught TypeError: array_key_exists(): Argument salesagility/SuiteCRM#2 ($array) must be of type array, Lead given in /var/www/vhosts/mydomain.net/subdomains/crm/public/legacy/modules/Campaigns/WebToPersonCapture.php:146 Stack trace:

0 /var/www/vhosts/mydomain.net/subdomains/crm/public/legacy/include/MVC/Controller/SugarController.php(1010): require_once()

salesagility/SuiteCRM#1 /var/www/vhosts/mydomain.net/subdomains/crm/public/legacy/include/MVC/Controller/SugarController.php(465): SugarController->handleEntryPoint() salesagility/SuiteCRM#2 /var/www/vhosts/mydomain.net/subdomains/crm/public/legacy/include/MVC/Controller/SugarController.php(361): SugarController->process() salesagility/SuiteCRM#3 /var/www/vhosts/mydomain.net/subdomains/crm/public/legacy/include/MVC/SugarApplication.php(101): SugarController->execute() salesagility/SuiteCRM#4 /var/www/vhosts/mydomain.net/subdomains/crm/public/legacy/index.php(52): SugarApplication->execute() salesagility/SuiteCRM#5 /var/www/vhosts/mydomain.net/subdomains/crm/public/index.php(54): require('...') salesagility/SuiteCRM#6 {main}" while reading response header from upstream`

Possible Fix

From AI diagnostics, it suggested this:

_The error message "PHP Fatal error: Uncaught TypeError: array_key_exists(): Argument salesagility/SuiteCRM#2 ($array) must be of type array, Lead given" suggests that there is a type error in the code of the WebToPersonCapture.php file in the Campaigns module of SuiteCRM 1 . The error is caused by passing a variable of type "Lead" instead of an array to the array_key_exists() function. This error can be fixed by modifying the code in the WebToPersonCapture.php file to ensure that the correct type of variable is passed to the array_keyexists() function. It is recommended to seek the help of a developer or SuiteCRM support to fix this error.

Steps to Reproduce

  1. Create a Campaign List
  2. Create a web-to-person form.
  3. Copy code, create HTML page on web server.
  4. Browse the page, submit the form.
  5. Set SuiteCRM to PHP 7.4.33 and repeat the the form submission to find it works.

Context

Your Environment

PHP 8.0.28 (PHP-FPM) PHP 7.4.33 (PHP-FPM) MariaDB 10.4 Apache 2.4.37 Rocky Linux 8.6

SuiteBot commented 1 year ago

This issue has been mentioned on SuiteCRM. There might be relevant details there:

https://community.suitecrm.com/t/v8-3-0-lead-generation-form-produces-error-500-on-submission/89052/2

johnM2401 commented 1 year ago

Hey!

Thank you for raising this issue.

I've transferred this to the SuiteCRM-Core repo, as you've noted this is an issue you've found in SuiteCRM8

For reference's sake, it looks this is is a duplicate of the following issue: https://github.com/salesagility/SuiteCRM-Core/issues/209

J-Wick4 commented 1 year ago

I have found the solution to this bug and verified it works.

Edit the file: modules/Campaigns/WebToPersonCapture.php on line 146

Replace if (array_key_exists($k, $person) || array_key_exists($k, $person->field_defs)) {

With if (property_exists($person, $k) || array_key_exists($k, $person->field_defs)) {

lukio commented 1 year ago

Hi @J-Wick4, @clemente-raposo @johnM2401 I understand that this fix should be added to https://github.com/salesagility/SuiteCRM repository (v7.x) instead of this one. The 7.14.x is the end of PHP 7.4, so we could add it to the next ESR of 7.x.

J-Wick4 commented 1 year ago

Hi @J-Wick4, @clemente-raposo @johnM2401 I understand that this fix should be added to https://github.com/salesagility/SuiteCRM repository (v7.x) instead of this one. The 7.14.x is the end of PHP 7.4, so we could add it to the next ESR of 7.x.

I think from my research, the problem exists on both 7.x and 8.x. so maybe check both versions to be sure.