Skip Navigation

[Closed] CRED Create and insert parent member id shortcode

This support ticket is created 10 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

This topic contains 19 replies, has 3 voices.

Last updated by tony 10 years, 7 months ago.

Assisted by: Bigul.

Author
Posts
#77515

Hello

I have a situation where I have members amd clubs and am creating a many to many relationship via a third table called memberships.

To do this I want to add a simple button on the club page that is a CRED form that pre-selects all of the fields needed to create the link.

I can do all of the following:

- pre-define the post title
- pre-define the post slug
- pre-define the default values for membership data fields
- pre-define the club parent
- eliminate all space taken up by the above
- display the create button

What I cannot work out is how to automatically define the member parent.

What I think I need is some sort of shortcode that enables me to embed the member_id in the member parent CRED field.

I can get this value via a VIEW as follows:

NORMAL VIEW
Members, ordered by post date, descending, limit to 1 item
Select posts with the author the same as the current logged in user

VIEW LAYOUT
Unformatted
Field= ID

Because I have a Member/user relationship I am able to select the relevant member record but what I cannot do is plant that value in the CRED form.

==========
<div class="cred-field cred-field-_wpcf_belongs_member_id">
<div class="cred-label">member Parent</div>
[cred_field field="_wpcf_belongs_member_id" value=""]
</div>
==========

What I am trying to achieve is a situation where the user does not need to select any parents to create the many to many relationship. To do so would involve selecting from 100+ clubs and 2000+ members!!

I hope that I have explained this sufficiently - any help much appreciated.

(I checked the book review example https://toolset.com/documentation/user-guides/cred-forms-for-child-content/ but this only handles the pre-selection of the book - I assume that to identify the reviewer, the user needs to select themselves from the list of reviewers)

Tony

#77718

I just tried replacing the standard CRED field with a generic field:

[cred-generic-field field="_wpcf_belongs_member_id" type="hidden" class=""]
{
"required":1,
"validate_format":0,
"persist":1,
"default":"[wpv-view name="Get Member ID"]"
}
[/cred-generic-field]

but this does not work.

#77968

Bigul
Supporter

Hi Tony,

Please try it with CRED hook cred_before_save_data. Please check following link for more details.

https://toolset.com/documentation/user-guides/cred-api/

Please let me know your feedback

--
With Regards

Bigul

#77982

Thanks Bigul

CRED hook is not something that I am familiar with. I have had a look at the page given and found the part that you suggest trying but am unclear about what to put where and also how to embed the member ID. Is member ID obtained via my View?

add_action(‘cred_before_save_data’, ’my_before_save_data_action’,10,1);
function my_before_save_data_action($form_data)
{
// if a specific form
if ($form_data[‘id’]==12)

{

if (isset($_POST[‘my_custom_field’]))

{

// remove this field data

unset($_POST['my_custom_field']);

}

}
}

More help requested please.

My CRED form number is 724
The field I am trying to set is [cred-generic-field field="_wpcf_belongs_member_id" type="hidden" class=""]
The View is [wpv-view name="Get Member ID"].

Tony

#78988

Bigul
Supporter

Hi Tony,

Please check this thread https://toolset.com/forums/topic/cred-forms-for-child-content-on-original-parent-post/ . Hope it will help you.

Please let me know your feedback.

--
With Regards

Bigul

#78993

Hi Bigul

I did read that thread before but it does not cover what I want to do.

I am creating a membership post which defines a many to many relationship between member and club.

I can pre-select the parent for club (because the form is embedded on that page) but cannot pre-select the member parent. The only way I can define the member parent is my having the user select it or by running the VIEW which displays the member number. I just need to find a way of getting that number automatically included in the CRED.

Another way of looking at this is to apply a VIEW filter to the parent select, something that would be useful as an future development. By this I mean using a view to filter down the parent choice offered to a user.

Thanks
Tony

#79239

Bigul
Supporter

Hi Tony,

Please add the following code in your CRED form. Hope it will work.

[cred_generic_field type="hidden" field="_wpcf_member_belongs_id"]
{
"value":[view-shortcode-here],
"persist": 1
}
[/cred_generic_field]

This solution assumes the user will get the member parent id he wants from a views short code. Please make sure field name "_wpcf_member_belongs_id" is correct and the views shortcode actually returns only a value, the value you needs, so you will have to disable any filters, meta, etc.. in the view[View using for the short code].

Please let me know your feedback.

--
With Regards

Bigul

#79273

Hi Bigul

I added

===

[cred_generic_field type="hidden" field="_wpcf_belongs_member_id"]
{
"value":[wpv-view name="Get Member ID"],
"persist": 1
}
[/cred_generic_field]

===
to my CRED form but it did not work. My View has a filter to select the member_id. It does, however, only return one value "821".

I tried both

"_wpcf_member_belongs_id"

and

"_wpcf_belongs_member_id*

I then decided to try hard coding the 821.

=====

[cred_generic_field field="_wpcf_belongs_member_id"]
{
"value":821,
"persist": 1
}
[/cred_generic_field]

====

which did not work so I then added:
[cred_field field="_wpcf_belongs_member_id" value="821" order="date" ordering="desc" no_parent_text="No Parent"]

which worked fine.

I am not sure if there is a syntax error but it is odd that the hard coded generic field failed.

Any suggestions?

Tony

#79284

FYI The view that I use is as follows:

Members, ordered by post date, descending, limit to 1 item
Select posts with the author the same as the current logged in user.

The filter can only return 1 value and pagination is disabled.

#79439

Hi Bigul

I think that what I am asking to do is beyond what I should expect from the Types support team. I will await the developments re user integration and maybe try a few other possible solutions.

Please can you close the thread and many thanks for your help, which is much appreciated.

Tony

#79619

Hello Tony,

it seems that the issue is not resolved yet.

The way to achieve what you want , is through this method
of using a generic field which takes its value dynamically from another shortcode.
In this case a views shortcode.

We have similar solutions and they work.

In order for this to be resolved as quickly as possible,
can you please provide the complete output of the view shortcode (for example by inserting the shortcode in a page or post by itself)
Not the output of the shortcode when inside a cred generic field.

The reason for this is that a view has many other elements when rendered (wjhich do NOT display in the browser)
like filters, javascript etc..

All these will break the json format of the cred generic field and if you are using PHP 5.2.x (as i think you do)
it will just fail silently and display nothing.

Thank you

#79621

UPDATE:

in you example where you used the value hardcoded in a generic field,
a type of this field was not specified (is it a select, a hidden field, a textfield?)

So this would not work

You can just generate a generic field using the GUI and add the views shortcode
as a value to this field,

but first we got to make sure that the view shortcode returns only a single value and nothing else

#79668

Hi Nikos

I set up a new page with the only content being the view: [wpv-view name="Get Member ID"]

The page source code is:

===
<h1 class="post-title">TEST VIEWS PAGE</h1>

<div class="post-entry">

<!-- wpv-loop-start -->

821

<!-- wpv-loop-end -->
</div><!-- end of .post-entry -->

===

You can see the page at:
hidden link

The CRED field that I used was:
[cred_field field="_wpcf_belongs_member_id" value="821" order="date" ordering="desc" no_parent_text="No Parent"]

Regards
Tony

#79672

Hi Tony,

exactly, the HTMl comments inside the view area, break the JSON format
of cred generic fields shortcodes

JSON is a very strict format, HTML comments returned by the view shortcode are just text (inside the cred generic field)
that is incompatible with JSON format

Also i suggest you create the generic field usign the GUI so that it is setup correctly.
Just use the view shortcode as a value for that field (you can select a hidden generic field type so the user does not have to manipulate it)

Make sure these comments and everything else (except the actual id itself)
is removed from the view shortcode

It should work then.

#79697

Hi Nikos

Some progress. I understand the points you make.

I reduced the view down to the single code (I think). I added three consecutive views in page hidden link and they displayed with a single space between them. The comments are no longer there.

I then created a generic field and embedded the view, which did not work.

I adjusted the generic field to hardcode the member-id and it did work.

=====================================
[cred_generic_field field="_wpcf_belongs_member_id" type="numeric" class=""]
{
"required":0,
"validate_format":0,
"persist":1,
"default":"821"
}
[/cred_generic_field]
======================================

I have tried variuos combinations:

numeric / textfield
default / value
[wpv-view name="Get Member ID"] with and without ""

I have displayed the view shortcode immediately behind the input field (hidden link) (line 549)

It seems that the generic field does not recognise the view shortcode as it does not display anything in the input field. When I hardcoded the 821 it was visible in the input field.

Tony

[cred_generic_field field="_wpcf_belongs_member_id" type="textfield" class=""]
{
"required":0,
"validate_format":0,
"persist":1,
"value":[wpv-view name="Get Member ID"]
}
[/cred_generic_field]

[wpv-view name="Get Member ID"]

The topic ‘[Closed] CRED Create and insert parent member id shortcode’ is closed to new replies.