Problem: I have a form that allows Guests to submit a new post. I would like to show a modal that requires registration before the new post can be submitted.
Solution: Since there is no public JavaScript API for Forms, I don't have any examples to share for displaying a modal and requiring registration before submission. Instead, you could create two separate forms on two separate pages. Here are some more details and some sample code you can check:
- Create the first form, which should create new posts of some type in draft state
- Add the form to a custom Page
- Create another custom Page that will eventually contain the second form
- Set the form to redirect to a custom page that will contain the second form
- Add some custom PHP code using the CRED API that appends the new post ID to the redirect URL:
add_filter('cred_success_redirect_1234', 'custom_redirect_for_form_with_id_1234', 10, 3); function custom_redirect_for_form_with_id_1234( $url, $post_id, $form_data ) { $newurl = $url . "?postid=" . $post_id; return $newurl; }
- This means the redirect will now include the new post ID in the URL as a parameter. We will use this to assign the new post to the new User later.
- Create the second form, which will create new Users
- Add a generic field and set the value of the generic field to be the same as the URL parameter "postid" using the wpv-search-term or wpv-post-param shortcode.
- Insert the second form in the correct custom Page
- Add some custom PHP code using the CRED API that modifies the author of the new post when the new User is created, using the generic field value. Something like this:
add_action('cred_save_data_2345', 'new_user_author_action_2345',10,2); function new_user_author_action_2345($user_id, $form_data) { // Create post object $args = array( 'ID' => $_POST['your-generic-field-slug'], 'post_author' => $user_id ); // change the post author wp_update_post( $args ); }
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
https://codex.wordpress.org/Function_Reference/wp_update_post
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 |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 3 replies, has 2 voices.
Last updated by 6 years, 8 months ago.
Assisted by: Christian Cox.