I understand your goal.
Yes, we'll need to save the Post at least once before we can add RFG in the Front End with Forms.
The process would be (classically), to create an Add Posts Form, redirect that to another form, where you can add RFGs.
To make this smoother, you can:
- In your "Add Posts" form, redirect to any page, where you will insert the "Add RFG" Form
- In the RFG Form, in the field where you are supposed to choose the post the RFG belongs to, set it to listen to an URL parameter, like this example:
[cred_field field="@rfg.parent" class="form-control" output="bootstrap" select_text="--- not set ---" urlparam="belongs_to"]. urlparam="belongs_to" is what you want to set.
- Now you need to tell the "Add Posts" Form, which redirects to the Page where the RFG Form is, to add the above URL parameter urlparam="belongs_to", to the URL. You can do this with the Forms API Hook here:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect
The code for this is very simple, you'll just take the existing redirect URL (which you set in the Add Posts Form) and append a URL parameter:
add_filter('cred_success_redirect', 'custom_redirect',10,3);
function custom_redirect($url, $post_id, $form_data)
{
if ($form_data['id']==27) {
//return '<em><u>hidden link</u></em>';
$url = $url . '?belongs_to=' . $post_id;
//error_log(print_r($url, true));
}
return $url;
}
- Now insert the RFG Form in the Page where to the Post Form redirects.
If you now submit a Post with the "Add Post" Form, you'll be redirected to that page with the RFG Form.
Since you placed above code in the Theme's Functions File or in Toolset > Settings > Custom code, the URL param ?belongs_to=POSTID is added to the URL.
POSTID here is the ID of the post you just created with the Add Post Form.
Since the RFG Form listens to that URL parameter, it'll set the parent (the post it belongs to) automatically to the post you just created.
The problem now here is that after AJAX Submit the Field is not updated with the still existing URL parameter, that is a problem that we'd have to solve with some JS, I'll come back to this after some tests.