This topic is locked

Dynamic fields not working in Version 11

12/13/2025 13:07:24
PHPRunner General questions
D
DealerModules authorDevClub member

This all started with article from a few years back. Implemented and worked great.
https://xlinesoft.com/blog/2015/12/04/storing-field-labels-and-visibility-rules-in-the-database/

I was using Dynamic Fields in version 10.9, switched to 11.1 and it is partially working. Tried the upgrade to version 11.2 and still not working.
I can hide the field but cannot change the name, make it read only or make it required. So only can hide or unhide the field.

Is there something different with Version 11 vs. Version 10.9 that would cause this?

My Events / View page / Before display code:
// Code for dynamic fields.
global $strTableName;

$sql="select * from dynamic_fields where tablename='".$strTableName."'";

$rs = CustomQuery($sql);

while ($data = db_fetch_array($rs)) {

if ($data["visible"]!=1) {

$pageObject->hideField($data["field"]);

}

}
//End of code for dynamic fields.

My Events / View page / After table initialized code:
// Code for dynamic fields.
global $field_labels, $tables_data;

$sql="select * from dynamic_fields where tablename='".$table."'";

$rs = CustomQuery($sql);

while ($data = db_fetch_array($rs)) {

$field_labels[$table][mlang_getcurrentlang()][GoodFieldName($data["field"])]=$data["label"];

if ($data["readonly"]==1)

$tables_data[$table][$data["field"]]["EditFormats"]["edit"]["EditFormat"]="Readonly";

if ($data["required"]==1)

$tables_data[$table][$data["field"]]["EditFormats"]["edit"]["validateAs"]["basicValidate"][0]="IsRequired";

}
// End of code for dynamic fields.

Don't know if some of these functions were dropped in Version 11.1.

Thanks for any direction.

Paul

ChatGPT 12/13/2025

Hi Paul,

It seems you're encountering issues with PHPRunner after upgrading from version 10.9 to 11.1 and then to 11.2, particularly with the dynamic fields setup that previously worked well. Let's break down the potential causes and solutions for the problems you're facing.

Changes Between Versions

PHPRunner does undergo changes and improvements between versions, which can sometimes affect custom code. While the specific changes between 10.9 and 11.x may not be extensively documented, here are a few suggestions to verify and troubleshoot your current implementation:

  1. Check Documentation: First, review the release notes for versions 11.0, 11.1, and 11.2 to see if there are any noted changes regarding field properties or the handling of dynamic fields.


  2. Field Visibility: In newer versions, there might be changes in how field visibility and properties are handled. The hideField function still should work, but the way properties like "readonly" and "required" are set might have changed. Ensure that the $tables_data structure you're using is compatible with the new version.


  3. Debugging: Add some debugging lines in your After Table Initialized event to check if the fields are being processed correctly. For instance, you can log the values of $data to see if you're correctly fetching the readonly and required values.

    // Debugging
    file_put_contents('debug.log', print_r($data, true), FILE_APPEND);

  4. Correct Field Names: Ensure that the field names you are dynamically setting with labels and properties match the names used in the database and in PHPRunner. Any mismatches could cause your settings to be ignored or not applied.


  5. Check for Overwrites: Make sure that no other scripts or settings in your project are overwriting the settings you are applying in your events. This can happen if there are other event handlers or settings in the UI that are conflicting.



Code Review

Your code looks generally correct, but ensure that you are using the right keys for $tables_data. Here’s a slightly modified version that includes some checks:

// After table initialized
global $field_labels, $tables_data;
$sql="SELECT * FROM dynamic_fields WHERE tablename='".$table."'";
$rs = CustomQuery($sql);
while ($data = db_fetch_array($rs)) {
$fieldName = GoodFieldName($data["field"]);
// Set field label
$field_labels[$table][mlang_getcurrentlang()][$fieldName] = $data["label"];

// Set readonly property
if ($data["readonly"] == 1) {
$tables_data[$table][$fieldName]["EditFormats"]["edit"]["EditFormat"] = "Readonly";
}

// Set required property
if ($data["required"] == 1) {
$tables_data[$table][$fieldName]["EditFormats"]["edit"]["validateAs"]["basicValidate"][0] = "IsRequired";
}
}

Final Steps

  • Testing: After adjusting your code, test each property (visibility, readonly, required) individually to see if any of them work correctly. This can help isolate the issue.
  • PHPRunner Support: If the issue persists, consider reaching out to PHPRunner support or their community forums. They may provide insights specific to version changes or offer solutions that are not covered in the documentation.

I hope this helps you troubleshoot the issue! If you have further questions or need more assistance, feel free to ask.

Sergey Kornilov admin 12/13/2025

This is code is not supposed to work in version 11. It doesn't use APIs but relies on internal project structures like $tables_data that no longer available in version 11.

This code needs to be re-written to use APIs for functionality like hiding fieldsm making then required and settings fields labels. Here are respective links in the manual:

Hide a field:
https://xlinesoft.com/phprunner/docs/hidefield.htm

Make field required:
https://xlinesoft.com/phprunner/docs/ctrl_addvalidation.htm

Settings field label:
https://xlinesoft.com/phprunner/docs/setfieldlabel.htm