Skip Navigation

[Resolved] Populate CRED form with 2 parents

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to display CRED form with parent post of current logged in user and add two parents

Solution:
To display CRED parent field which displays only current logged in user posts, you need to following the steps given in the following reply:

You can find the proposed solution with the following reply:
https://toolset.com/forums/topic/populate-cred-form-with-2-parents/#post-404588

Relevant Documentation:

This support ticket is created 7 years, 10 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.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 24 replies, has 2 voices.

Last updated by Geoffrey Cleverley 7 years, 10 months ago.

Assisted by: Minesh.

Author
Posts
#405580

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I can see on the following link there are members available:
your-site.com/wp-admin/edit.php?post_type=member

Now, I've question that, you have added code in JS box for members, you mean you want to display only members created by logged in users with the dropdown?

members are parent of reviews, so how come we decide which member should be parent of review?

#405588

My site is membership based. Each user can create only one member profile.

Reviews are Children of both Books and Members.

Each review must be assigned to a Book parent post and the Member parent post of the currently logged in user.

When a user is viewing a Book post, there is a link to 'review this book', when they click this link they are taken to the Book review page.

The Book parent selector is prepopulated already, with the book post from the originating link.

As my site may have hundreds of users, each with a member post, I needed the Member parent post selector to only include, and if possible, better yet be prepopulated with the current users Member post.

The php function I added to my themes function.php and the javascript on the form, that you gave me at the beginning of this support thread, worked perfectly, in that it only displayed the member post of the currently logged in user in the dropdown.

So the dropdown basically had one member post available to select.

Brilliant, thank you Minesh.

However the dropdown would still require the user to select the Member post to assign it to. The default state was 'no parent selected'...

It would be great, if it was possible to prepopulate the Member parent field with the currently logged in users Member post. So that when they clicked the 'review this book' link they were taken to a CRED Book review post form that had both of its parents (Book & Member) already assigned.

Then the user could just write their review, and submit, without having to touch any selection dropdowns.

It would be even better if the Member post parent selector was hidden as then the user experience would be more seamless.

(I decided not to hide the Book post parent selector as it functionally lets them know which book they are reviewing, but seeing their Member post is unnecessary).

---

In short, I would like the parent selector for:

[cred_field field='_wpcf_belongs_member_id' value='']

To be prepopulated/autopopulated with the Member post of the currently logged in user, and hidden.

---

I must apologise for asking for so much help, the function and javascript you provided me worked brilliantly and I hope I am not asking too much.

Jeff

#405664

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I understand now what you need.

Now - As you said each user will have one member profile but as you can see now:
=> hidden link

I've added another dropdown field for parent member:

[cred_field field='_wpcf_belongs_member_id' value='']

But I dont think you've setup member for my logged in user. Could you please setup and then hopefully in next reply I'll write jQuery to make dropdown option preselected so user do not have to select it.

#405672

Hi Minesh,

It is currently set up so that the only option available in the Member parent dropdown selector is the Member post of the current user. (using the function and jQuery you previously provided)

When the page first loads the dropdown includes all users member posts, but when it finishes loading the only Member post available is the one of the current user.

Thanks

Jeff

#405674

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I understand this - but as you can see on the following form:
hidden link
[ Please login with account you setup for me]

If you see member parent dropdown - its only showing "No Parent" option with parent member dropdown.

What I'm saying that as you said before that each review should have at least one member. So could you please setup one member for my account so it should be seen as dropdown option with above member parent dropdown.

I hope you get what I'm saying. I understand your all functionality but I just want to see one member option in parent member dropdown.

#405679

Ah, now I got you.

Your user account has no Member parent. I'll remedy that. You were quite clear, my bad.

#405680

Done.

#405685

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've added following jQuery code to your CRED form's JS box:

 $('select[name=_wpcf_belongs_member_id] option:eq(1)').attr('selected', 'selected');
  $('select[name=_wpcf_belongs_member_id]').attr('disabled', true);

Now - you can see member profile selected automatically 🙂

I hope this will help you to achieve what exactly you were looking for and help you to resolve your issue.

#405687

That is brilliant, thank you Minesh, this was one of my last real issues before I can start building the structure of my real site, and the main one that was holding me back.

You're a true gent, I am incredibly grateful.

Jeff

#406476

UPDATE:

Issue needed further resolution, Minesh pointed me in the right direction to give me the submission flow I wanted in the thread below.
https://toolset.com/forums/topic/part-2-of-populate-cred-form-with-2-parents-thought-resolved-but-isnt/

1.Remove this part of JQuery code, as it stops the member selector writing to database:

$('select[name=_wpcf_belongs_member_id]').attr('disabled', true);

2. Then make the CRED Member parent selector a required field to ensure no user deselects their member post:

[cred_field field='_wpcf_belongs_member_id' value='' order='date' ordering='desc' required='true' select_text='--- Select member ---' validate_text='member must be selected']

Nice one.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.