Link to a record

FRW

Well-known member
I have a custom formatting function to shorten long text in a textfield:
[pre]
function dadabik_kurz_150 ($value){
if ($GLOBALS['function'] === 'search' && strlen_custom($value) > 150){
return nl2br(substr_custom($value, 0, 150).' ...mehr');
}
else
{
return nl2br($value);
}
}
[/pre]

Is it possible to insert a link to the specified record, so I can make a click on "...mehr" to go to the detail-page?
 

eugenio

Administrator
Staff member
About the first part, it's safer to do something link

if ( isset($_GET['function']) && $_GET['function'] === 'search' & ...

Also, nl2br should be already provided by dadabik.

About the link, you can't use dadabik_link here, you have to provide the actual URL (you have in input the id of the record).

Best,
 

FRW

Well-known member
Thank, I modified this, but:
How to get the id ? $value only offers the text...

Is there a global for input? How have I to ask for id?
 

eugenio

Administrator
Staff member
It's a value you get in input: check the documentation in custom_functions.php:

"each custom formatting function receives in input the value to display $value and the value of the unique field of the record processed ($id)"

Best,
 

FRW

Well-known member
My custom_functions.php says:
...nothing else.

And the try:

[pre]
...
return substr_custom($value, 0, 150).'...mehr';
...
[/pre]
will leave the "...$where_value=" blank
 

eugenio

Administrator
Staff member
Sorry, my fault! I got confused with the upcoming 10.2 that will have this new input value!

So at the moment it is not possible (unless your $value is the unique field itself).

Best,
 

FRW

Well-known member
For all the other:

I've updated to 10.2 and it works with this in custom_formatting_functions.php:

[pre]
function dadabik_kurz_150 ($value,$where_value){

if ( isset($_GET['function']) && $_GET['function'] === 'search' && strlen_custom($value) > 150){
return substr_custom($value, 0, 150).' ...mehr';
}
else
{
return $value;
}
}
[/pre]
 

eugenio

Administrator
Staff member
Correct; I would add urlencode to the code: urlencode($where_value)
If id is numeric, it's not needed.

Best,
 
Top