Link element placeholders

NickC4555

Active Member
Is there any way of using placeholders for link element label and URL values? I want to render a formatted link in a calculated element. Using {member_news___website} and {member_news___website_raw} both display the entire value stored in the database, i.e. {"label":"Blog \u2013 BGM Rhythms","link":"http:\/\/bgmrhythms.wordpress.com\/"}
 
If you really need to store it in a calc element...
PHP:
$url = '';
$label = '{member_news___website}';
$val =  '{member_news___website_raw}';
if(!empty($val)) $url = '<a href="http://' . $val . '">' . $label . '</a>';
return $url;
But if you're just trying to create a link - and nothing that needs to be saved to the database or used elsewhere - why not just add some code (in the form_#.js file) to add it 'on-the-fly'?
JavaScript:
if ( jQuery("#member_news___website").text().length ) {
    var label = jQuery("#member_news___website").text();
    var val =  jQuery("#member_news___website").val();
    var url = '<a href="http://' +  val + '" class="jsUrl">' + label + '</a>';
    jQuery(url).appendTo('div#addToDivId');
}
Where 'addToDivId' is the id of a div in the form where you want to append the url. The jsUrl class (or any class name you want to use) is optional - but can be used for css styling.

That could be shortened a bit with...
JavaScript:
if ( jQuery("#member_news___website").text().length ) {
    var url = '<a href="http://' +  jQuery("#member_news___website").text() + '" class="jsUrl">' + jQuery("#member_news___website").text() + '</a>';
    jQuery(url).appendTo('div#addToElementid');
}
 
Thanks for your reply. I need for users to be able to separately enter URLs and anchor text, which are rendered as a link in a calc element. I assumed the link element type would be suitable, but as I said in my original post, {member_news___website} and {member_news___website_raw} don't work. They both return. {"label":"Blog \u2013 BGM Rhythms","link":"http:\/\/bgmrhythms.wordpress.com\/"}.

I have used two separate field elements to get the job done.
 
If you just want to render that link in a calc ...

Code:
$myLink = '{member_news___website}'
if (!empty($myLink)) {
   $myLink = json_decode($myLink);
   return '<a href="' . $myLink->link . '">' . $myLink->label . '</a>';
}
return 'no link!';

-- hugh
 
If you just want to render that link in a calc ...

Code:
$myLink = '{member_news___website}'
if (!empty($myLink)) {
   $myLink = json_decode($myLink);
   return '<a href="' . $myLink->link . '">' . $myLink->label . '</a>';
}
return 'no link!';

-- hugh

Much appreciated, thank you.
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top