Categories > TinyButStrong general >

onformat question

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: bert
Date: 2003-10-27
Time: 13:16

onformat question

Thank you for making TBS available. It's a great tool! I have a question.
If a summary field contains a link, I want to make html-code and display it like a link.
php-code:
function makelink($FieldName,&$CurrVal) {
   
    // replace link with <a href> etc.
     $CurrVal['summery'] = eregi_replace(
        "(http|https|ftp)://([[:alnum:]/\n+-=%&:_.~?]+[#[:alnum:]+]*)",
         "<a href=\"\\1://\\2\" target=\"_blank\">\\1://\\2</a>",
         $CurrVal['summery']);

   // add hard returns
   $CurrVal['summery']=nl2br($CurrVal['summery']);

}

html-side:
[product.summery;block=table;onformat=makelink; htmlconv=no]

In one script this works fine, in another script is doesnot work.

Can you help?

By-the-way: The manual is not consistent: you mention "fct_name" vs. "nom_fct" and "$CurrRec is the current value" should be "$CurrVal is the current value". And a small typo: "passed by refrence" should be "passed by reference".
By: Skrol29
Date: 2003-10-27
Time: 14:24

Re: onformat question

hi Bert,

There is a bad bug on version TBS 1.81 with the "onformat" parameter and the "block" paremeter used together.

I suggest that you separated them, and choose the correct function syntaxe depending on what you what the "onformat" to go with.

Thanks for your comment abour the documentation.
I currently working on it.
By: bert
Date: 2003-10-27
Time: 16:13

Re: onformat question

hi Skrol,

Thanks for your quick reply.
1) not clear what you meant by "separate". But I changed to "explicit syntax".
2) I think I did not use onformat correctly: In the manual there are two places where you explain onformat. I use the section in Merge-Fields. When I change "&$CurrVal" in "&$currRec" then it works fine!
so the php-side:
function makelink($FieldName,&$CurrRec) {
    // replace link with <a href> etc.
     $CurrRec = eregi_replace(
     "(http|https|ftp)://([[:alnum:]/\n+-=%&:_.~?]+[#[:alnum:]+]*)",
     "<a href=\"\\1://\\2\" target=\"_blank\">\\1://\\2</a>",
     $CurrRec
     );
    $CurrRec = nl2br($CurrRec);
}
and
html-side:
[product.summery; onformat=makelink; htmlconv=no]
Does the job!

Kind regards,

P.S. Maybe use this in Examples? Currently no example for onformat...
By: Skrol29
Date: 2003-10-27
Time: 16:24

Re: onformat question

Yes i meant to use the "onformat" and "block" parameters in two different TBS tags. For example, using the explicit syntax like you've done.
You can also use relative syntaxe but puting "onformat" in one tag, and "block" in another tag.
The "block" parameter doesn't need to be in the first tag.

This bug will be corrected in the next version.
This version is finished to be coded now but I'm still working on the doc.

Yes It's also a good idea to give an example on the "onformat" parameter. This can help often. I'll do it.


By: bert
Date: 2003-10-27
Time: 16:33

Re: onformat question

Thx for the explanation. Looking forward to the new version.
By for now.