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.
Update:
I deactivated the code snippet but the association still does not form.
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.
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
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?
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
I used the style equals display: none in the class to hide the field and that worked.
My issue is resolved now. Thank you!