Whenever I try to save a user's profile info, even my own, I get this error message. Note: It only happens for a few users, not all. Any idea what the issue is? Thanks
ErrorException: [E_WARNING] Undefined array key "regex" in src/XF/CustomField/Definition.php at line 428
XF::handlePhpError() in src/XF/CustomField/Definition.php at line 428
XF\CustomField\Definition->_validateMatchTypeRegex() in src/XF/CustomField/Definition.php at line 267
XF\CustomField\Definition->_validateFieldTypeTextarea() in src/XF/CustomField/Definition.php at line 243
XF\CustomField\Definition->_validateFieldTypeTextbox() in src/XF/CustomField/Definition.php at line 230
XF\CustomField\Definition->isValid() in src/XF/CustomField/Set.php at line 203
XF\CustomField\Set->set() in src/XF/CustomField/Set.php at line 108
XF\CustomField\Set->bulkSet() in src/XF/Admin/Controller/User.php at line 378
XF\Admin\Controller\User->XF\Admin\Controller\{closure}() in src/XF/Mvc/FormAction.php at line 166
XF\Mvc\FormAction->run() in src/XF/Admin/Controller/User.php at line 563
XF\Admin\Controller\User->actionSave() in src/XF/Mvc/Dispatcher.php at line 352
XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line 258
XF\Mvc\Dispatcher->dispatchFromMatch() in src/XF/Mvc/Dispatcher.php at line 115
XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 57
XF\Mvc\Dispatcher->run() in src/XF/App.php at line 2487
The error message you're encountering, "Undefined array key "regex"", indicates that the code is trying to access a key named "regex" from an array, but that key doesn't exist. This is happening specifically in the CustomFieldDefinition class at line 428 of the src/XF/CustomField/Definition.php file.
Here's a breakdown of what's happening:
The CustomFieldDefinition class likely represents a definition for a custom field in a user profile.
The code expects a validations array to be present within the definition, and for the "regex" key to be set within that array if the field type is "textarea".
However, in some cases, the validations array might not have the "regex" key set, causing the error.
This error only occurs for a few users because the validation logic is likely only triggered under specific conditions, possibly when a specific custom field type is being saved.
Here are some possible solutions you can try:
Fix the code: If you have access to the codebase, you can fix the issue by ensuring that the validations array always has the "regex" key set, even if it's an empty string. This would prevent the error from occurring.
Update the plugin or software: If this is a known issue with a plugin or software you're using, there might already be an update available that fixes the problem. Check for updates and install them if available.
Inspect the data: Investigate why the "regex" key might be missing for some users. There could be a data integrity issue or a bug in the way the data is being processed.
Well after some investigating with another person, this seems to be well beyond the scope of a regular “end user” I think…..
What we have been able to determine thus far……with everything up to date.
I do not believe we have a database issue. I looked for crashed tables and such, and there does not appear to be any. If its database related then it’s an entry within some table or something.
I also verified that the server itself doesn’t seem to be an issue – plenty of disk space is available (199G on the /home partition).
So I went and looked at the code that was referenced. It appears to me to be something that is pretty “hard coded” as opposed to something that you might have defined. Basically someone created a special function called “validateMatchTypeRegex” which they are then calling from within a plugin or something. Problem is that there are no comments or other breadcrumbs to indicate what might have put this in.
This custom field is a regular, built-in “official” part of Xenforo and not a plugin.
I looked at the change timestamp and noted it was updated at 2/5/24 @ 12:20. So I did a search for all files changed on 2/5/24. The bottom part (after the blank lines) were all changed at 12:20 so I cannot narrow it down except to say it was not in the “addons”.
I then did a search of the database for the word “regex” in any of the fields. I found it in several of the databases.
So we browsed the xf_user_field and found the column “match_type” where some stuff has regex and some doesn’t (attached as xf_user_field.png – note screenshot taken after adding the TestMe field mentioned below)
We then did some testing to determine what does/doesn’t work.
We noted that user ID 4 was unable to edit and save any field – we tested with some that had the regex in the match_type column and some that doesn’t.
We then added a new custom field named TestMe (match_type = none) and attempted to edit that with the user. It also didn’t work.
We then chose another user (ID 632) and edited fields on her account. All fields were successfully editable, including the new TestMe field.
We also tested on another user with higher privileges (thinking it might be that user ID 4 has advanced privileges) and were not able to reproduce this issue with any other users.
We did have another user who previously had an issue and it was “fixed” by merging the account with an older account they also had.
During the test saving, I was watching the mysqld.log for any messages, but none appeared.
So the concern is we cannot figure out why ID 632 would not be a problem whereas ID 4 would be, and where we might look for an answer. Additionally, because of this, we have no way of knowing how many other users might be impacted, or how to find them.
Neither of us are programmers (much less Xenforo developers) and even if we attempted to try to follow support’s recommendation of changing the codebase, honestly I wouldn’t have the foggiest idea how to do that.