Skip Navigation

[Resolved] Include a repeater field into a form

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.

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 6 replies, has 2 voices.

Last updated by Minesh 1 year, 9 months ago.

Assisted by: Minesh.

Author
Posts
#2647035
repeater-form.jpg
page.jpg
lightbox.jpg

Tell us what you are trying to do?
I created a ticket regarding contribution forms, and it will soon be continued. However, when creating the form, I encountered an issue with repeater fields. I've read through the documentation and found out that I need to create a standalone form to address the repeater fields. I've done that (see image). Then, I created a page and initially placed the repeater field form within a Lightbox frame using a shortcode. Afterward, I embedded the main form using Forms. In the main form, I added a link at the specified location that calls up the repeater field form.

The form does appear, but with an additional dropdown menu labeled with the CPT (Custom Post Type) name and no selection options. Moreover, it's a simple form that doesn't provide the option to save multiple records.

What I want is for the user of the form to be able to fill out repeater fields in the frontend without leaving the main form.
Is there any documentation that you are following?
https://toolset.com/documentation/programmer-reference/forms/cred-shortcodes/#cred_form
https://toolset.com/course-lesson/front-end-forms-for-repeatable-field-groups/

Is there a similar example that we can see?

What is the link to your site?
hidden link (under construction)

#2647077

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

When you add a child form (repeating field group) form it will not get the parent reference. Can you please share details where exactly you added the repeating field group form - is it on the parent post page? If yes: then you can set the default value attribute for your parent dropdown that is available with your child form (repeating field group form) select for value attribute : value="[wpv-post-id]"

Does that works?

If that does not help, please share admin access details and problem URL where I can see the issue.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2647141

Minesh
Supporter

Languages: English (English )

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

Ok I see you have a add new form to add new post for the post type "websites" using the form "projekt-erstellen".

So in that case you will have to first add the new post using the form you have "projekt-erstellen".

So for instance you have already added the form here:
- hidden link

On submit of this form, you will have to redirect the user where you added a child form.

For that, you should add a new page for example "Add Filialen" that should hold your child form (repeating field group form) so add the following form to this newly created page and save your page
- hidden link

Then you can use the "cred_success_redirect" hook to redirect user to the "Add Filialen" page you created with URL param that holds the parent website post ID.
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect

For example:
- you can add the following code to "Custom Code" section offered by Toolset or functions.php file of your current theme:
=> https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/

add_filter('cred_success_redirect', 'func_redirect_to_child_post_add_page',10,3);
function func_redirect_to_child_post_add_page($url, $post_id, $form_data){
    if ($form_data['id']==82265 ){
         
        $actual_link = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]/add-filialen/";
        $actual_link = $actual_link."?parent_webseite_id=". $post_id ;
       return  $actual_link;
    }
          
    return $url;
}

Where:
- 82265 is your parent form ID
- 'add-filialen' is your page slug that holds the child form to create new repeating field group post

Please let me know how it goes as you will have to first add the parent post and once parent post is added we will get the parent post ID and then we will be able to create child (repeating field group) posts.

#2647147

I'll try, but the issue I'm facing is that my form is structured as follows:

Question 1 -> Answer: A, B, C -> If the answer = B => display the "Filialen" form => else, display something else

This structure is used in 5 different places, so I need a solution that doesn't send the user to a new page each time he wants to add information to a repeatable field. I could also program something on my own, like an Ajax request to load the "Filialen" form or load it via an iframe.

For now i restructure the "first form" so it can be saved and try to replicate your advice.

#2647151

Minesh
Supporter

Languages: English (English )

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

Let me try to explain you again, the repeating field group is managed as one-to-many post relationship where the parent post where you add the repeating field is parent and all items you add to the repeating field group will be treated as child.

As you may know some code so you can understand that without creating parent (without having parent ID)we can not connect the repeating field group items you create to the parent post.

So it must require you to go step by step. First you should create a parent post and then redirect user to the another page where you added the repeating field group form. This is the standard flow. As you must create parent first in order to connect the repeating field items to its parent.

I hope this is clear now.

#2647295
form-mini.jpg

I believe I've understood the logic behind the setup. I've added a form for creating the CPT "Webseiten" and another form for editing it. Then, I've created a content template that loops through the created CPTs for the author only. Additionally, I've created another content template in which the form is embedded, and also included the "Filialen" subform in it. I've added a custom edit link to the loop. It works in such a way that I can create and edit a CPT.

However, the second form, "Filialen," is being displayed, but it can't find the ID of the opened CPT. I tried: [cred_form form="subform-filialen"], [cred_form form="subform-filialen" post=[wpv-post-id]] and [cred_form form="subform-filialen" value=[wpv-post-id]]. In all cases it displays the dropdown menu to select the CPT. In this menu i can select the CPT and add Data to the CPT via the repeater Field.

Besides that there is one big problem. The CPT have to be "private" so only the author is able to read and edit them but if I set them to private, the repeater field is unable to find them (I am not sure if this is a topic of a seperate ticket or its related enough to stand here)

#2647507

Minesh
Supporter

Languages: English (English )

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

Can you please share details what forms you created now and where exactly with what page you are displaying those forms and to what page you want to display what form.

I have set the next reply to private which means only you and I have access to it.

#2656101

I found another way to solve my form, i used the single repeater fields