Tell us what you are trying to do?
-I am trying to create a Toolset Cred form that would allow a user to submit on 1 form that would create multiple posts under a CPT. For instance, a user has their profile information(name, email, phone) to submit and then has 2 children that each have their own name, birthday, and eye color. This form would get the user's name, email and phone then have a children section that is a repeatable field group. If the user adds 2 children, on submit the form would create one post with the User's name, email, & phone then child #1's info then a second post with the User's Name, Email, & Phone but with child #2's info.
Or maybe I am going about this the wrong way.
Is there any documentation that you are following? None that I have found.
Is there a similar example that we can see? None that I have found.
Hi, in general Toolset Forms are limited to creating or editing a single post (or User). Repeatable Field Groups are considered as posts in this case, since they are technically implemented as child posts of the parent post in a one-to-many post relationship. So unfortunately the current User experience isn't as streamlined as you have described unless you implement a significant amount of custom code. The workflow in the current system would be something like this:
- Your client submits a Form to create one Parent post. The Form automatically redirects the client to the Parent single post.
- In the single Parent post template you display information about the Parent post, and a View of RFGs related to that Parent post, so the client can see a list of current RFGs. Obviously that View will be empty at first, but will grow as RFGs are added.
- A link to edit each RFG is included in each row.
- In the single Parent post template you also display a button to create a new RFG. That button will redirect the User to a Form to create a single RFG row. The Form automatically redirects the client to the Parent single post, where the new RFG row is shown in the View of RFGs.
- From the single Parent post, the client can click to edit any single RFG row on a separate page.
Beyond that, it sounds like you want to be able to automatically create some Child posts based on the RFGs submitted. So I'm wondering, since it's not possible to add/edit RFGs in a parent Post Form are the RFGs even necessary? In other words, your clients could just as easily create Child posts instead of RFGs in the previous scenario.
Please let me know your thoughts and we can go from there.
Well after thinking it over maybe another route would be to allow our user to submit the basic form with 1 child's information, but have 2 options for submit. 1 Submit option would be to complete the form and send them to a normal confirmation page, but the other button would submit the current data sets, but keep the Parent Info field values, while clearing the child info.
This would allow the user a similar experience where they are still submitting the required data per entry, but not require them to refill out the parent info part. It would be better to do this within the page so it wouldn't have to reload the page, but if need be maybe on submit of the form it reloads the current page, but passes along the parent info fields via the URL as attributes and per populates the fields on the page reloading? Thoughts?
This would allow the user a similar experience where they are still submitting the required data per entry, but not require them to refill out the parent info part.
In the scenario I was describing, the parent info is only filled in once, in step 1. In the other steps, the parent info is just displayed and not re-entered or editable in any form inputs. If you want to display the parent post information on the new Child Post Form, that is certainly possible once the parent is created, but it is not currently possible to create or edit the parent post and also create or edit a child post in a single Form without custom code. If you want to allow Users to edit the parent post after it is created, you can show an edit Parent post Form separately from the add/edit Child post form.
After thinking my needs over I really need each submission to be their own entries within a CPT. I don't want to have parents posts and child posts. So maybe going a different route completely would effectively achieve my goal.
What if I create a form that does a conditional redirect based upon a field value. The user fills out all required information. At the bottom there is a required yes or no field. If the user selects no, the form submits regularly and redirects to a normal Thank you page. If a user selects yes, the form submits the data then redirects back to the same form URL by using a similar method like this https://toolset.com/forums/topic/cred-user-form-conditional-redirect/#post-956463 , but will also pass attributes in the URL.
Based upon those set urlattributes I can use this method to populate the form with the correct data, while leaving the new data cleared out. https://toolset.com/forums/topic/pass-cpt-field-value-to-a-cred-form-on-another-page/
Doing this allows me to have each submission be its own custom post type entry and not have a parent/child relationship. Thoughts?
Seems okay to me, just remember that you can only edit or create one post at a time in one Form. So after the first post is created with "Yes" checked, the page reloads. The original post is displayed somehow (in another Form or just as regular text), and a Form is shown to create another new post. Just remember here that you cannot edit the original post in the same Form used to create a new post without custom code. Also it's probably not necessary to use URL parameters for all the values in the original post, because by the time the page reloads that original post has already been saved. You can display the existing values from the database without relying on URL parameters.
So I am trying to setup my conditional redirect based upon a generic checkbox field. Here is what I currently am doing. I have all of my other fields in my form, but at the bottom I have a checkbox generic field. If the user doesn't check the box, it will submit the data and then go to the first URL, currently going to Google (plan to change to a generic thank you page). If the user checks the box the form will also submit the data, but go to a different URL. Currently, the form is correctly setting the first URL, but I am having issues detecting value of the generic field. What am I doing wrong?
In Cred Form:
<label>Add An Additional Distributor</label>
[cred_generic_field type='checkbox' field='multi-dist']
{
"required":0,
"default":""
}
[/cred_generic_field]
In Functions:
add_filter('cred_success_redirect', 'custom_redirect',10,3);
function custom_redirect($url, $post_id, $form_data){
if ($form_data['id'] == 127515 ){ // this is my form ID
$type = get_post_meta($post_id,'multi-dist',true);
$url = '<em><u>hidden link</u></em>' ;
if ( $type == true ){
$url = '<em><u>hidden link</u></em>';
}
}
return $url;
}
By chance are you still able to help with this or should I open a different ticket as I am going a different route now?
Hi, sorry I was out yesterday but I'm still able to help here. It looks like your generic checkbox field has no value, and also you're trying to access the value in postmeta. A generic field doesn't necessarily store values in postmeta, so it's better to check in the $_POST superglobal to determine whether or not a generic checkbox was checked.
[cred_generic_field type='checkbox' field='multi-dist']
{
"required":0,
"value":1,
"default":""
}
[/cred_generic_field]
$type = $_POST['multi-dist'];
Hey! Sorry I didn't realize you were out of the office. Thanks for getting back though.
So I actually was able to do something similar by using the code below, but now I am having the second part of my issue where I am wanting to append some URL params via the URL based upon some of the values submitted via the form.
Below you can see I am trying to set a variable from the post meta for textfield eu-first-name. Then I am trying to concatenate that variable to the end of the URL string.
Functions Code
//Shortcode for URL Redirect
add_filter('cred_success_redirect', 'custom_redirect',10,3);
function custom_redirect($url, $post_id, $form_data){
if ($form_data['id'] == 127515 ){ // this is my form ID
$eu_fn = trim(get_post_meta($post_id,'eu-first-name',true));
$url = '<em><u>hidden link</u></em>';
if ( array_key_exists('multi-dist', $_POST) ){
$url = '<em><u>hidden link</u></em>'. $eu_fn;
}
}
return $url;
}
Form Field Code
[cred_field field='eu-first-name' force_type='field' class='form-control' output='bootstrap' urlparam="eu-fn"]
With the above code I get redirected with the URL of : hidden link
If this is a custom field created in Types, you should use the "wpcf-" prefix when attempting to get information using get_post_meta:
$eu_fn = trim(get_post_meta($post_id,'wpcf-eu-first-name',true));
Any time you are accessing custom fields through native WordPress functions (like get_post_meta), you need to prepend the wpcf- prefix to the slug.