Skip Navigation

[Resolved] Repeateable field add form for load parent in related field

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

Last updated by francescoG 1 year, 5 months ago.

Assisted by: Minesh.

Author
Posts
#2616955

Tell us what you are trying to do?
I created a form to add a repeateable field to my custom post type
I insert this form in single template of parent post, and I want that related field have to preloaded parent value so I add this field to my form

[cred_field field='@candidatenotes.parent' class='form-control' output='bootstrap' value="$current" required="true"]

I seams to work becouse I have the correct value in form but when I submit I have this error

Fatal error: Uncaught InvalidArgumentException: All provided arguments for a related element must be either an ID or a WP_Post object. in....

could you help me please

#2616979

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

It seems you will have to connect the post when you submit the form.

Can you please share problem URL where you added the form as well as admin access details.

*** 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.

#2617021

Minesh
Supporter

Languages: English (English )

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

I installed the adminer plugin on your site and I can see that you have two post types available with the same slug "candidate":
=> hidden link

I'm not sure what post type you are using or the correct one.

Can I go ahead and delete the first "candidate" row?

#2617115

Sure, you can

#2617873

Minesh
Supporter

Languages: English (English )

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

I've reported the issue to our next level support. Please hold on for further updates.

#2618241

Minesh
Supporter

Languages: English (English )

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

Can you please check now: hidden link

I've removed the parent field from your form:
=> hidden link

And added the following code to the "Custom Code" section offered by Toolset with the code snippet name "connect-candidatenotes":
=> hidden link

add_action('cred_submit_complete', 'func_connect_candidate_notes',10,2);
function func_connect_candidate_notes($post_id, $form_data) {
     
  if ($form_data['id']==5205){
    
    if (isset($_POST['_cred_cred_prefix_cred_container_id'])){
      	
       $parent_post_id = $_POST['_cred_cred_prefix_cred_container_id'];
        toolset_connect_posts('candidatenotes',$parent_post_id,$post_id);
    }
    
  }
    
}

Can you please confirm it works as expected.

More info:
=> https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts

#2618511

Yes it works as I expected.
But I have to questions
1) where did you add that php code?
2) For the future, because I don't know php, why didn't work my solution? I don't undestand where was the problem. Could you say me why?

#2618995

Minesh
Supporter

Languages: English (English )

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

1) where did you add that php code?
==>
I already shared that information with my previous reply.

And added the following code to the "Custom Code" section offered by Toolset with the code snippet name "connect-candidatenotes":
=> hidden link

More info:
- https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/#adding-custom-php-code-using-toolset

2) For the future, because I don't know php, why didn't work my solution? I don't understand where was the problem. Could you say me why?
==>
It was not working because you have added the $current to select the current post in the parent dropdown box. But as you can see now with your form I already deleted the parent dropdown box as its not required and added the code I shared that does the trick.

#2619523

My issue is resolved now. Thank you!