Skip Navigation

[Resolved] Association not formed on form submit

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

Problem:

Disable the relationship field, but submit the relationship field value.

Solution:

If you disable a HTML select field, it won't be able to post parameters to Toolset Forms.

In your case, you can add a hidden generic field into your post form, for example:

https://toolset.com/forums/topic/association-not-formed-on-form-submit/#post-1904851

Relevant Documentation:

This support ticket is created 3 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/Hong_Kong (GMT+08:00)

Tagged: 

This topic contains 7 replies, has 2 voices.

Last updated by himanshuS 3 years, 11 months ago.

Assisted by: Luo Yang.

Author
Posts
#1903297
association not formed.png

I have two post types: expert review request and expert match.

I am unable to form relationship between the two when I submit the expert match form. (screenshot attached)

I am also using following code on the form to populate custom fields:
add_action('cred_save_data', 'populate_expert_info',10,2);
function populate_expert_info($post_id, $form_data)
{
// if a specific form
//$forms = array( 11046, 11072);
// $relationship_1_slug = "parent-child-relationship-slug";
// $ms_field_slug = "your-multiselect-field-slug";
if ($form_data['id']==11046 || $form_data['id']==11072)
{
$expert_id = $_POST['generic-expert-name'];
$user_info = get_userdata($expert_id);
$username = $user_info->first_name;
update_post_meta($post_id,'wpcf-matched-expert-id', $expert_id);
update_post_meta($post_id,'wpcf-matched-expert-name', $username);

}
}

What could I be missing?

Steps to replicate: (need to sign in as admin)
Step 1 -Go to hidden link
Step 2- select a card and go to the card's post. It is the expert review request post
Step 3 - click on match expert button
Step 4 - you will be directed to expert match form
Step 5 - form already has the link with the expert review request post. Now submit the form
Step 6 - you reach expert match form but there is no relationship formed between the two post types.
Step 7 - you can go to wordpress expert match post and see the expert id and expert name custom fields get populated but no association is formed in "expert-review-request-to-expert-match" relationship.

#1903367

Update:
I deactivated the code snippet but the association still does not form.

#1904249

I found the issue.

I am using a custom JS provided by toolset to disable change to the relationship field from the front end (because I want the parent post to come from url param and the user should not be able to change it.

The JS script:
(function( $ ) {
$('select[name="@project-submission-to-expert-review-request.parent"]').attr('disabled',true)
})(jQuery);

How can I form an association on the form and still disable change on relationship field in the front end.

#1904851

Hello,

If you disable a HTML select field, it won't be able to post parameters to Toolset Forms.

In your case, you can add a hidden generic field into your post form, for example:

[cred_generic_field type='hidden' field='@project-submission-to-expert-review-request.parent' urlparam="parent-page"]
{
"default":""
}
[/cred_generic_field]

Please replace the "parent-page" with the specific URL parameter name

It will pass the parent post ID too.

More help:
https://toolset.com/documentation/programmer-reference/forms/cred-shortcodes/#cred_generic_field

#1905581

It does not seem to work.

The generic field does not form associations when I submit the post.

The generic field value also is not called when I use $_POST['field'] function.

Example: $parent_post_id = $_POST["@project-prompt-to-project-submission_parent"]; //get parent post ID from form

I really need to do the following:
1) Hide the parent post relationship on the form
2) Create an association on post submit
3) Retrieve the relationship field parent post id to run custom code.

This all happens when I use the standard relationship field but I can't hide that field.

What can we do here?

#1905969

I have tried it in my localhost, it works fine, if you still need assistance for it, please provide a test site with the same problem

#1905971

I used the style equals display: none in the class to hide the field and that worked.

#1905973

My issue is resolved now. Thank you!