Skip Navigation

[Resolved] Use repeating field values as options for a field on a CRED form

This support ticket is created 8 years 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Tagged: 

This topic contains 5 replies, has 2 voices.

Last updated by Beda 8 years ago.

Assisted by: Beda.

Author
Posts
#380562

Is there a way to use the values from a repeating field as options for a field on a CRED form?

I have a type called 'Applicants', which has a field 'CVs', which stores files. This is a field which can have multiple values.

I want to create another form where I choose an applicant, and then choose one of the multiple files related to that applicant, and store the URL for that file in one of the fields on the new form.

Then when the form is submitted I can send the link to the chosen file in a notification.

#380845

Theoretically yes, everything or almost everything is possible with code.

Not with Toolset features though.

1. Views (the tool you would need to populate a Field dynamically) is not intended to be used as a Data generator but as a Data display engine

2. Repeating Fields are a array. It would actually be less painful if you would have those Files as single Fields or Post Types.

Bottom line, it can only be done with Custom Code.

What I can show you is a theoretical possible approach, but we do not support this and it's not intended to be used to be honest.

- You would create generic Select Fields in CRED and populate with Views, which return a JSON valid data.
- Please read this post on how to return JSON in a View, and what steps to take:
https://toolset.com/forums/topic/views-result-array-as-shortcode-parameter/
- If you set the generic Fields to "persist=1" then they get saved to the Database and you can display them after everywhere constructing a custom ShortCode that get_post_meta() the meta_value of those fields

But as said, it is possible while not suggested.

I hope this can help you to achieve your goal

#380870

Thanks Beda

I have another way of doing things that might be simpler.

If I have one field that is a single field for storing the most recent CV and then another repeating field to store older CVs then I can send the notification with the single (most recent) CV.

But then what I need to do is when I want to save a new (most recent) CV I need to move the existing most recent CV to the array of older CVs.

Ideally this should happen when I try to delete the most recent CV, it should automatically send this to the array of older CVs, or something like that? Is there a before_delete hook or something that I can use to add this code? I don't know if it would be possible to add some kind of button or link so I can delete or replace the most current CV? Any pointers on how I can achieve this?

#381163

There is a before_save_data (which also is before it deletes data) hook, https://toolset.com/documentation/user-guides/cred-api/#cbsd

But I am not sure this will help you achieve your goal, as the second field is array.

You will need to use a advanced PHP Logic here, as you can not simply update_post_meta() as a "normal" meta_value.

Either you fetch the correct value in the array and update that, or you update the whole array every time you update the Field (less wanted I think)

I apologize that your goal this way is not quickly achievable.

I would probably think of another setup, if I would want to do this with Toolset only and no or less custom code.

As example with a parent / child relation or similar.

Then you could have a "picker" that allows you to choose the required Data in the CRED's.

Please let me know if you have further questions regarding the issue mentioned in this Thread

Thank you for your patience.

#381230

Hi Beda

I'm not sure I understand what you mean by using a parent / child relationship and a 'picker' allowing me to choose the required data?

Can you explain what you mean?

#381272

When you have a parent Child Relation ship, CRED Lets you create a CRED Form for creating a Child post.

In that Form by default a "Parent Post Picker" will be included, which allows you to choose one parent post for the editing / creating Child Post.

If you would set a Post Type where you include ONE of your Fields (which now are repetitive) you could then pick that Post from within the Child CRED Form.

The Post Type (parent) would hold the Field only, which now is repetitive on your end.

To have many instances of this "field", you would then create new posts.

If you would need to associate many Fields (repetitive) to your Child, you would additionally need a Intermediate Post Object Type.

This is elaborated here:
https://toolset.com/documentation/user-guides/many-to-many-post-relationship/
https://toolset.com/documentation/user-guides/creating-post-type-relationships/
https://toolset.com/documentation/user-guides/creating-groups-of-repeating-fields-using-fields-tables/
https://toolset.com/documentation/user-guides/cred-forms-for-child-content/

Thank you

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