Using Database Fields in Comcode Page

Post

Posted
Rating:
#5776 (In Topic #1185)

Adding from the cms_f_member_custom_fields table

I am trying my hand on my first Comcode Page.  I want to pull some fields from the cms_f_member_custom_fields table. 

The tempcode  works on the f_members table.  I also want to pull from the cms_f_member_custom_fields table.  The custom profile fields are in a different table than what the $CPF_VALUE tempcode works on.

I know how to program a php page to do this, not inside Composr.  What is the proper way to do this with a Comcode Page?

Thanks so much!
 

Post

Posted
Rating:
#5779
f_member_custom_fields holds CPF values, and CPF_VALUE was originally designed to use them.
It being able to get f_members fields is a bonus feature for it.
Try passing the field ID number, or the field name.

Post

Posted
Rating:
#5780
Thanks Chris!

I tried to use the CPF_VALUE tempcode, but it does not pull the f_member_custom_fields values (unless I am doing this incorrectly).  I want to let members print out a stylized page, based upon their database custom field inputs.  I thought Composr's WYSIWYG editor was a great option, because I can add the Comcode page to their panel, use the custom fields, and the Comcode pages have a link at the bottom of the page for printing. 

I haven't been able to figure out how to use a Comcode page to do what I am trying to do.  Is this possible with a Comcode page?  

Am I better off creating a php page without the WYSIWYG editor?   Can the page still be linked in the member's Menu dropdowns?

Thanks again!

Post

Posted
Rating:
#5781
Perhaps a mini-block would work? You can then include these on your Comcode page like any other block.

Post

Posted
Rating:
#5783
Thank you Adam, for trying to help me!

Post

Posted
Rating:
#5784
CPF_VALUE is working fine for me. If I do this on my test site, after setting the default First name field to test on my admin account (account #2)…

Code

{$CPF_VALUE,First name}
{$CPF_VALUE,firstname}
{$CPF_VALUE,42}
{$CPF_VALUE,First name,2}
{$CPF_VALUE,firstname,2}
{$CPF_VALUE,42,2}

I get…

Code

test
test
test
test
test
test

If you're not able to get it working, please provide full details on what is not working for you (name of the CPF, how it is configured, the Tempcode you are using), and we will try and help.

Here I'm using 3 different syntaxes the CPF_VALUE symbol accepts for looking up CPFs (written name, internal codename, field ID), and testing both for the current user and with an explicit member ID.

Post

Posted
Rating:
#5814
Sorry, I've been away.  Thanks for responding Chris.

I found that if I refer to the name of the field in the cms_f_member_custom_field database (ex: field_59) it does not display the field.  If I refer to the field by the number (ex: 59), it does display.

It looks like a comcode page won't work for me as such, as I have some fields that are "a paragraph of text (no comcode support)".  The parapgraph contents of those fields therefore do not display.

I could create the php page the way I want it and embed it into a comcode page, possibly using an iframe.  Does this sound reasonable?  Is it good practice to only use all comcode pages, even embedded ones?

Thanks again!

 

Post

Posted
Rating:
#5818
Try {$CPF_VALUE,59,{$MEMBER},1}

Post

Posted
Rating:
#5821
Thanks so much for responding, Chris.  I apologize for not being clear.  

works.  Thanks for your help.

A different field (field_47) is "a paragraph of text (no comcode support)".  I am unable to display the contents of this field.
 

Post

Posted
Rating:
#5822
Ok, try {$CPF_VALUE,47,{$MEMBER},1}

The '1' should make it parse the Comcode.

Last edit: by Chris Graham

Post

Posted
Rating:
#5823
Thanks for trying to help me, Chris!

As for field_47, which is "a paragraph of text (no comcode support)".....

did not display anything.
 

Post

Posted
Rating:
#5834
Odd, it should work, and does in my tests.

I should clarify, the final '1' isn't actually for Comcode specifically, it determines to show the 'rendered' value of a field. That can mean many things based on field types. For Comcode fields, that means rendered Comcode.

But I see now you said "a paragraph of text (no comcode support)" (I misread).

"No Comcode support" is not saying it won't work on a Comcode page, it's saying the contents of the field can't be Comcode (so no tags etc).

It really should just work in a very straight-forward way, with or without the final 1.

Make sure the user you are testing really does have something in the actual field ID you are referencing.

You should also have an asterisk if using in a page without the final ",1".
{$CPF_VALUE*,47,{$MEMBER}}
I don't want to get into a long discussion on how HTML escaping works here, but it's important to convert non-HTML to HTML when putting it into a page for security reasons, and without the final ",1" the symbol is not going to be returning HTML.

Post

Posted
Rating:
#5837
Thanks Chris!

I couldn't get things to work the way I wanted so I decided to create a php page, in a folder not inside Composr.  I then used an iframe to insert that page into a Comcode page.  I did get an error message at one point:

Uncaught SecurityError: Blocked a frame with origin XXXX://XXXXXX.XXX from accessing a cross-origin frame.
XXXX://XXXXXX.XXX/XXXXXX/cms/index.php?page=cms-comcode-pages

I need users to be able to print out this page.  What is the best way to add this page to Composr?

Thanks again!

Post

Posted
Rating:
#5838
Well, I don't know if that error message corresponds to your frame, or something else. I see Facebook producing this kind of stuff a lot. I doubt you are writing cross-frame JavaScript code in what you're doing. And I doubt you have embedded your iframe from a different origin.

I would not recommend messing around with frames anyway though. They're very clunky in a number of ways. It's hard to get them to size correctly. They load separately to the main page, causing for example flicker, or at least slow loading. Unless styled very carefully they look disjunct from the rest of the page with their own border etc.

A mini-block is a lot more straight-forward. You just create a sources_custom/miniblocks/whatever.php file with your PHP code then include it into a page with [block]whatever[/block].

Post

Posted
Rating:
Item has a rating of 5 Item has a rating of 5 Item has a rating of 5 Item has a rating of 5 Item has a rating of 5 (Liked by Adam Edington)
#5840
Thank you for everything, Chris!

I created a miniblock as you suggested, using the tutorial on Composr entitled Hardcore Blocks.  I was able to use an iframe in a block.  The Comcode page makes it very easy for the user to print the information, and automatically adds the link to the user's menu.

Hope this helps someone else.

Thank you again!!!
5 guests and 0 members have recently viewed this.