This topic is locked

PHP to return the name of the current field?

11/1/2018 2:31:55 PM
PHPRunner General questions
K
klyle author

Other than the JS https://xlinesoft.com/phprunner/docs/field_getname.htm - is there a PHP way to get the name of the current field?

admin 11/1/2018

What kind of event we talking about? Most events like BeforeAdd or BeforeEdit executed once per page call and there is no "current" field.

K
klyle author 11/1/2018

Good question.
This is a piece of Custom PHP code, where it is called via an include from within a field. In this case, it is to draw a graph. It relates to my topic about sparklines.
Ideally, since I named the fields Chart7, Chart14, etc., where the NN is the number of days, we could extract the NN from the field name.
For the moment, we will try to pass the NN (number of days) in the code that calls the include. In that case, we can just define $days = 7; and that value will be available to the include code as well?
Thanks for the quick reply.

admin 11/1/2018

It makes sense. We do not have an API for this purpose. There are ways but they are not documented and may stop working in later versions. Defining a variable in the beginning of 'View as' Custom is certainly more reliable.