This topic is locked
[SOLVED]

 Change Labels on the fly

10/31/2010 3:55:31 AM
PHPRunner General questions
kujox author

How can I change the add/edit field labels on the fly?
I need to be able to pull the labels from a table and display those, this lets the user define the labels for certain custom fields.
I have a master table with a field named custom_field_01, for one user this may be a field to list colours while another user may want it to list materials, they define the label in an alias table so it's unique to each user.
I've tried making the variables global and then assigning the value in before process, process record, process sql and before edit events but they don't seem to work using the following code.



$field_labels[$strTableName]['English']['custom_field_01'] = 'colours';

$field_labels[$strTableName][$_SESSION["language"]]['custom_field_01'] = 'colours';
J
Jane 11/2/2010

Hi,
to replace labels with values from database use customevents instead of static labels on the Visual Editor tab.

kujox author 11/4/2010



Hi,
to replace labels with values from database use customevents instead of static labels on the Visual Editor tab.


I have been trying in the custom events but can't seem to find the array which holds them

kujox author 11/30/2010



I have been trying in the custom events but can't seem to find the array which holds them


Just to update in case anyone wants to do the same as me by holding the label alias in a table allowing the labels to be changed by an admin.



### BeforeProcessEdit

global $conn;
$sql = "SELECT field_name,details FROM labels_alias_products";

$result = db_query($sql,$conn);

while ($datarow = mysql_fetch_array($result)) {

$_SESSION['product_label_alias'][$datarow['field_name']] = $datarow['details'];

}


Then I added a code snippet in the edit page which replaced the label



echo $_SESSION['product_label_alias']['stock_custom_01'];


That's done the trick, it's not ideal as I didn't want to change the template or any code in the functions as was hoping just to insert the values into an array or a session variable