Skip Navigation

[Resolved] Can't edit repeatable field groups in post form

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

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

This topic contains 6 replies, has 2 voices.

Last updated by ericE-4 4 years, 11 months ago.

Assisted by: Waqar.

Author
Posts
#1468069
species-form.jpg

I am trying to allow users to edit the repeatable field groups of a custom post type. I have created a post form to allow a user to edit the post which they are an author of, and it is working (other than the bugs I've encountered and am working through).

I noticed that the post form builder did not allow adding fields for editing the RFG that are part of the posts (this was a terrible design decision on Toolset's part IMO), so I read on some other support topics that the RFG data for a post needs to be edited using a separate form.

So I created a separate form for editing the RFG "Fish Species". This form is displayed on the same page where the post form for editing the lodge is displayed. However, when I display the form I either get "No items found" or "Form type and post type do not match", depending on how I display it.

This is what I've done:

1. I've created a View that filters the posts by current author, so I can only show the post form for the Lodge post where the currently logged-in user is the author.
2. I've created the post form for the lodge. As mentioned this is working (sort of) and the user can edit the Lodge post which they authored.
3. I've created a post form for the Fish Species RFG. See species-form.jpg for how it's configured.
4. In the View I show both the form for editing the Lodge, then after that I show the form for editing the Fish Species RFG for that lodge, like this:

<wpv-loop>
  <div class="preview-link"><a href="[wpv-post-url]" target="_blank" rel="noopener"><i class="far fa-external-link-alt"></i> Preview page</a></div>
  [cred_form form='edit-lodge-details-page']
  [cred_form form='edit-species-lodge-details-page']
</wpv-loop>

I need to allow the user to edit the RFG while editing the Lodge post data, so once I get the RFG form showing, I will move the RFG form into a modal using javascript, and the user can click "Edit Fish Species" at the point in the Lodge form where Fish species should appear.

5. I also created a different view that also filters the posts by current author, but this one shows the RFG form only, like this:

<wpv-loop>
  [cred_form form='edit-species-lodge-details-page']
</wpv-loop>

I did this so that I could display the view, which would display the RFG form in a modal, which would appear when the user clicks "Edit Fish Species", as I described above.

When I display the page to edit the Lodge post, I see:
1. After the lodge form, where the RFG form should appear, it says "Form type and post type do not match".
2. In the modal, where I've embedded the view from 5., it says "No items found".

To replicate this:
1. Log in using the credentials below.
2. On the next page, click the button "Edit Lodge Details"
3. Scroll down to the "What we Catch" section and click "Edit Species" to see the results of the embedded View from 5.
Scroll down to the very bottom of the form to see the results of the embedded RFG form.

#1469351

Hi Eric,

Thank you for contacting us and I'd be happy to assist.

When no post ID is provided to the edit form's shortcode "cred_form" through the "post" attribute, it uses the ID of the current post in the loop.
( ref: https://toolset.com/documentation/user-guides/front-end-forms/cred-shortcodes/#cred_form )

When you're in the loop of a view that shows "Lodges" posts and use the form "edit-lodge-details-page", it works because the form can use the current post's ID for editing.

But in the same loop, it has no information about which "Fish Species" post to use for the editing form "edit-species-lodge-details-page", and this is why you see the message "Form type and post type do not match".

To make this work, you'll need to insert a child view that shows the "Fish Species" posts related to the current "Lodges" post and in that child view's loop, you'll place the shortcode for the form "edit-species-lodge-details-page".

As for the modal/popup, I noticed that you're using Elementor's popup feature, which loads the enclosed content on request and that content is not part of the page's markup when it is loaded.

As a result, Toolset Form placed inside the popup shows, but any script-based dynamic features ( e.g. date picker, AJAX submission, media library uploader, etc ) don't work as expected. If your enclosed form is expected to have any of these dynamic features, it would be best to use a different modal/popup feature that loads the content on page reload.

Example:
Popups - WordPress Popup
( https://wordpress.org/plugins/popups/ )

Note: The "No items found" message is showing as the view is trying to show the related "Fish Species" posts from the popup post from the Elementor plugin and not the current "Lodge" post from the parent view. This is another reason that you'll need to switch to a different popup/modal.

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#1470249
config.png

Understood about the issues with the popups. If I can get the Fish Species form displaying, I can then find the best way to display it in the UI.

You said: 'To make this work, you'll need to insert a child view that shows the "Fish Species" posts related to the current "Lodges" post and in that child view's loop, you'll place the shortcode for the form "edit-species-lodge-details-page".'

I've done this. I created a view to display the form for editing the Fish Species RFG. The view contains the the shortcode for the form "edit-species-lodge-details-page". I've placed the shortcode for this view on my page, below the shortcode to display the other view/form.

The view always returns "No items found".

Here is how I've configured the view (see config.png)

And here is the contents of the loop editor:

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
      <wpv-loop>
        [cred_form form='edit-species-lodge-details-page']
      </wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

What am I doing wrong?

#1470933

Thanks for writing back.

I noticed that the child view "Edit Species (Lodge Details Page)" wasn't actually nested inside the parent view "Edit Lodge Details Page".

The shortcodes of both these views were placed at the same level in the template.
( screenshot: hidden link )

The shortcode for the child view needed to be inside the loop of the parent view.
( screenshot: hidden link )

Note: you can remove the child view's shortcode from the template.

Also the child view "Edit Species (Lodge Details Page)" needed some adjustments too.

- in the content selection "Lodges" and "Fish Species" both post types were selected, when we only need "Fish Species".
- in the post-relationship filter, "The post where this View is shown" was selected without specifying the actual relationship.

I've selected the target relationship and "The current post in the loop" option, as this view is nested inside another view, from which we need the parent lodge post.
( screenshot: hidden link )

#1472239

Hi Waqar, and thanks again. Honestly, I never would have figured that out on my own as I just don't find it intuitive. And as Toolset documentation is scant (and poorly written IMO), I wouldn't be able to be successful with Toolset without you.

I'm getting there.

I now have my Lodge form also outputting the view for the Species repeatable field group. 🙂

Now I need to allow the user to add a new Species RFG. I figured out that this means I need to create a different custom form, one intended for adding new records only (not editing). I've done that, and created post form "add-species-lodge-details-page".

Inside my view that shows the post form for editing the each Species, I've placed a shortcode to display this "add" form like this:

[cred_form form="add-species-lodge-details-page"]

The problem is that the "add" form will only add a new record if I select the Lodge (the parent) from the select control (controlled by the Lodge relationships field). But the Lodge is known (this is all running in a loop for the current Lodge post) and I do not want to show this select field to the user. It's completely redundant, as there's only one value for Lodge that makes sense—the lodge that is currently being edited!

So how can I have the "add-species-lodge-details-page" form default the Lodge value to the Lodge that is being edited?

In the "add-species-lodge-details-page" form I tried to default the select field to the current post's title by using Expert mode and editing the field definition like this:

[cred_field field='@fish-species.parent' class='form-control' output='bootstrap' select_text='--- not set ---' value='[wpv-post-title]']

But that didn't work.

And related question that i would be asking eventually anyway is: How do I allow the user to DELETE a RFG?

#1473067

You're very welcome Eric and glad that we're making progress.

1. I noticed that in the "Lodge" field for the "Add New Species (Lodge Details Page)", "[wpv-post-title]" shortcode was used to pass on the default value in the "Field default value" option.

Your idea was correct, but instead of title, you'll need to pass the lodge's ID, using the "[wpv-post-id]" shortcode.
( screenshot: hidden link )

2. For deleting an RFG post, you can use the "cred_delete_post_link" shortcode in the loop of the same view, where you've have placed the form for editing them.
( ref: https://toolset.com/documentation/user-guides/front-end-forms/cred-shortcodes/#cred_delete_post_link )

To get the ID of the current RFG post in the loop, again you can use the "[wpv-post-id]" shortcode:

Example:


[cred_delete_post_link post="[wpv-post-id]" text="Delete this item" action="delete"]

#1483905

My issue is resolved now. Thank you!