Navigation überspringen

[Gelöst] Multistep Forms

This support ticket is created vor 3 Jahren, 5 Monaten. 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
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)

Author
Artikel
#2126609

However, the second one was created directly in the backend. And the posting form doesn't seem to pick it up.
Yes, as I said this second one is a draft post. It is not published. Only published posts will be included in the dropdown.

The second point goes about multistep form.
Let me make a couple of quick adjustments and give you an update, I think it will be more clear once I have made some changes for you. Please stand by.

#2126641

It seems the critical error was related to editing the post in Pending Review or Draft status. The Private status seems to work best for now, since I suspect you do not want the Editor Profile post to be public during this editing process. As a result, the Editor Profile post will only be visible to the logged-in User who created it and to Administrators while in this stepped editing process.

So I have updated Step 1 Form settings as such:
- Post status: Private
- After visitors submit this form: Display the post

I have updated Step 2 Form settings a such:
- Post status: Keep original status
- After visitors submit this form: Display the post

The submission flow is:
- User goes to versteckter Link to see the step 1 Form
- User submits the Form, and this creates a Private status Editor Profile post.
- User is redirected to see the step 2 Form at a dynamic URL like this: versteckter Link
The cred-auto-draft-*** portion of the URL will be different for every User submission, since the Editor Profile post is unique for each User.

I suggest applying similar settings in each of the subsequent Edit Forms to prevent the post type mismatch error:
- Post status: Keep original status
- After visitors submit this form: Display the post

That is up until the very last Form, which should set the post status as desired. If that status is not Private or Publish, the last Form should also redirect the user somewhere other than "Display the post", maybe to a custom Page with a message like "Your post is under review".

#2127485

Hi Christiaan,

We must have gotten our wires crossed here. There are two sets of multistep forms. The first one is the set of 4 forms Ie
New Editors Form Step 1. The purpose of this form is for a new potential editor to register his profile on the system (pending review). Once this is done, the admin will then check if they will accept the editor and if they do they will then approve the post where after the user can then log in, access his/her profile and complete the profile with the set of 9 multistep forms ie "Update Editors Profile Step 01".

So far in this process, we have established that the pending review does not work well with what we are doing and i think it was you that I rather use two options for the user roles Ie:

  • PEG - Editor Pre-Approval
  • PEG - Editor

The first form will create an entry with the pre-approval status. and this post will be published, however no record with pre-approval will show on the front end. Then the admin will approve the post, the status will draft and the user roll will then change to PEG - editor. This will then enable the editor to log in access his profile with the form starting with "Update Editors Profile Step 01". ass long as he/she has not completed the form it will stay as pending or private as you commented.

Once the 9 step form has been complete it will update to published and will then be available to the front end users in the search and filters.

Now my problem was with the "Update Editors Profile Step 01" form and not the New Editors Form Step 1. The register form worked 100% it should have. It is with the completeness form that I am getting the file and type error.

The URL where you can see the error is versteckter Link.
It is with the completeness form where I am also getting the error on when I am trying the edit the form that will now a private status with the user roll just as peg editor.

The error occurs don't this URL:
versteckter Link specifically at label :
After visitors submit this form: if i try to link a post in the go to specific post and i want to select any post it gives me the error.

I will change the registration form back to the previous setting just with the private status. If you then run it you will see it works. It is actually with form 2 that we are getting the error. I have just double-checked and I am getting errors now on both the forms.

The first one did work correctly because the cred enter was done wth the form.

I hope this clarifies my intention with the forms

#2127861

I'm making some necessary changes, but I'm currently unable to save updates to the functions.php file in wp-admin. Can you provide FTP access so I can update that file manually?

#2127865

Private reply fields are enabled here so you can share that information securely.

#2127869

Additionally, I'm seeing memory allocation errors now:

Allowed memory size of 134217728 bytes exhausted (tried to allocate 200704 bytes)

I can try to resolve that by adjusting the wp-config.php file if you provide FTP credentials.

#2127935

Got it, thanks. I added this information to the wp-config.php file to bump up the memory allocation:

define('WP_MEMORY_LIMIT', '256M');
define( 'WP_MAX_MEMORY_LIMIT', '256M' );

- To prevent the critical error message, I've modified each of the 9-step forms to redirect to the Profile Completeness page for now, we can adjust later if necessary but please do not change yet.
- I've updated the functions.php file to include updated content template IDs for the redirects applied to each of the 9-step forms. They were previously set up to redirect to Form IDs, but those number should be Content Template IDs instead.

The URL where you can see the error is versteckter Link. It is with the completeness form where I am also getting the error on when I am trying the edit the form that will now a private status with the user roll just as peg editor.
Lots of issues here. First let's address the form / post type mismatch error. It's related to the fact that no post was specified for the Edit Form, and the Form is displayed out of context. To fix that, I've created a custom shortcode that can be used to determine the current User's Editor Profile post ID. The custom shortcode will return 0 if no Editor Profile post is found for the current User. Here is the code, I have already added it to the functions.php file:

// Toolset Support reference: https://toolset.com/forums/topic/multistep-forms
// get the logged-in User's Editor Profile post ID
// used to inform Toolset's Edit Post Forms which profile should be edited
add_shortcode('current-user-editor-profile-id', function( $atts = [], $content='' ) {
  if( !get_current_user_id())
    return 0;
  $ep_args = array(
    'post_type'   => 'editor-profile',
    'post_status' => array('publish','pending','private','draft'),
    'author' => get_current_user_id(),
    'posts_per_page' => 1,
  );
  $ep_query = new WP_Query( $ep_args );
  $ep_id = isset($ep_query->posts[0]->ID) ? $ep_query->posts[0]->ID : 0;
  return $ep_id;
});

Next I registered current-user-editor-profile-id in Toolset > Settings > Front-end Content > Third-party shortcode arguments. That allows us to use this shortcode as an attribute in the edit post Form shortcode. I've updated the Edit Post Form shortcodes in each of the 9 "Editors profile completeness form" Content Templates to include the new shortcode pointing to the User's specific Editor Profile post ID, like this example in the first template:

[cred_form form='update-editors-profile-step-1' post='[current-user-editor-profile-id][/current-user-editor-profile-id]'][/cred_form]

You need a conditional around the Form, because an error will occur if no Editor Profile post exists for the current User. So I've added that conditional using the following conditional criteria:

NOT (
The result of [current-user-editor-profile-id] is equal to 0.
)

Basically this tests to see if the current User has an Editor Profile or not. If so, it will display the edit form. If not, nothing will be displayed.

Next I had to move my previously created Editor Profile post out of the trash to test the Form. So I moved it, and set the status again to Privately published.

After that, I was able to see the form as expected in the Profile completeness page (screenshot attached). I made a minor text adjustment and submitted the Form, and I was then redirected to see the next step form at the URL:
versteckter Link
So each time a step is submitted from here, the URL will update to include the content template ID containing that step form.

I will change the registration form back to the previous setting just with the private status. If you then run it you will see it works. It is actually with form 2 that we are getting the error. I have just double-checked and I am getting errors now on both the forms.
I'm not sure I understand what should happen after the User submits New Editors Form Step 1. Should they be redirected to see New Editors Form Step 2? If not, what should they see immediately after submitting New Editors Form Step 1? Please explain.

#2127945
Screen Shot 2021-07-28 at 10.09.06 AM.png
Screen Shot 2021-07-28 at 10.09.34 AM.png

Screenshots attached showing Profile Completeness steps 1 and 2 as I saw them during my test.

#2129785

Hi Christiaan,

Thank you for your assistance. I am working through it to make sure I understand everything. I do have one question though.

Why would you use a template instead of a shortcode to show a form on a page?

#2130865

Why would you use a template instead of a shortcode to show a form on a page?
The short answer is to prevent the form and post type mismatch error you have seen, and to allow you to integrate other features of Forms that expect the template approach. As I've been explaining, the Form needs to know which post it is supposed to edit if it is placed on an arbitrary page or post. The template approach solves that ambiguity without requiring you to write shortcodes.

We're trying to limit the use of shortcodes based on WordPress's decision to move towards the block editor for everything. In a Blocks design, the template approach is the simplest way to prevent the post type and form mismatch problem you have experienced when the Edit Post Form is shown on an arbitrary page. It is the approach documented in our course lesson for editing posts with forms - not only to prevent the form and post type mismatch error, but also because the Edit Post Link described in this section is designed to function in that template-based flow:
https://toolset.com/course-lesson/front-end-forms-for-editing-content/#3-insert-link-to-the-content-template-that-displays-the-form
In your case with stepped input and a more custom workflow, the template approach is not really ideal.

In the normal workflow, a post is displayed at a post URL like:
https://yoursite.com/post-type/post-title-slug/

An Edit Post Form would normally be a single step form, and would be displayed at a URL like this:
https://yoursite.com/post-type/post-title-slug/?content-template-id=12345

...where 12345 is the ID of the template containing the Edit Post Form. You are using a non-standard workflow that deviates from this normal scenario by displaying the Edit Post Form in multiple stages at an arbitrary URL. When you insert a cred_form shortcode to display the Edit Post Form in an arbitrary page or on another post URL, you must take other steps to prevent the form and post type mismatch error, and you cannot use the Edit Post Link feature as documented.

This is why we are using a custom shortcode to determine the User's Editor Profile post ID. We pass that information into the Form shortcode's post attribute to set an explicit post ID...so the Form knows exactly which post to edit, even though it is displayed on an arbitrary page URL:

[cred_form form='update-editors-profile-step-1' post='[current-user-editor-profile-id][/current-user-editor-profile-id]'][/cred_form]

That prevents the mismatch error normally seen when you drop an edit post form in an arbitrary page. However, you cannot use the Edit Post Link feature to create automatic links to that edit post form when you use a Form shortcode like this. It is a more custom approach that requires other kinds of links to navigate to the Edit Post Form.