• Resolved sstaples99

    (@sstaples99)


    Hi,

    I would like to create a form with multiple pages that submits on the last page. Is it possible to do this with ACF extended?

    Many thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • vy name

    (@vy-name)

    I too was looking at this today and found the following answer from the help of Brave AI. I will be trying this out today/this week. Perhaps it would help you?

    To create a multi-stage form using the Advanced Custom Fields (ACF) plugin, you can follow these steps:

    First, you need to create a field group that will contain the form’s fields. You can do this by going to the ACF > Custom Fields menu in your WordPress dashboard and clicking on the “Add New” button.

    Next, create a new form from the ACF > Forms menu and assign the field group to the form. Once saved, the form will now map the fields from the field group. This means those fields will be usable directly from the UI.

    To create a multi-stage form, you can use the Dynamic Forms module in ACF Extended. This module allows you to create a form with multiple stages, each with its own set of fields. You can configure the form to navigate between stages based on user input.

    Here’s an example of how you can use the Dynamic Forms module to create a multi-stage form:

    // Create a new form
    acf_form(array(
        'post_id' => 'your_post_id',
        'form_name' => 'My Multi-Stage Form',
        'fields' => array(
            array(
                'key' => 'field_1234567890',
                'label' => 'Stage 1',
                'type' => 'text',
                'required' => 1
            ),
            array(
                'key' => 'field_9876543210',
                'label' => 'Stage 2',
                'type' => 'text',
                'required' => 1
            )
        ),
        'dynamic_form' => array(
            'stages' => array(
                'stage_1' => array(
                    'fields' => array('field_1234567890'),
                    'next_stage' => 'stage_2'
                ),
                'stage_2' => array(
                    'fields' => array('field_9876543210'),
                    'next_stage' => 'done'
                )
            )
        )
    ));
    
    // Add a hook to handle form submission
    add_action('acf_form_submitted', 'my_form_submitted');
    function my_form_submitted($form) {
        // Get the current stage
        $current_stage = get_current_form_stage($form['post_id']);
    
        // Check if the form is completed
        if ($current_stage == 'done') {
            // Do something when the form is completed
        } else {
            // Navigate to the next stage
            wp_redirect(get_permalink($current_stage));
        }
    }

    In this example, we’re creating a form with two stages: stage 1 and stage 2. Each stage has its own set of fields. The form will navigate to the next stage based on user input. When the form is completed, it will trigger the my_form_submitted hook and do something when the form is completed.

    Note that you need to have the ACF Extended plugin installed and activated to use the Dynamic Forms module.

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback!

    Unfortunately it is not possible to have a multi step form that only submit one time. However, you can chain multiple forms that will follow each other, and make it multistep. Each step being one form that is submitted and saved.

    You can use the acfe_is_form_success() helper (see documentation) to know when one step has been submited to display the next one. Usage example:

    // no form was submitted
    if(!acfe_is_form_success()){
    
        // display form-step-1
        acfe_form(array(
            'name' => 'form-step-1'
        ));
        
    // form-step-1 was submitted
    }elseif(acfe_is_form_success('form-step-1')){
    
        // display form-step-2
        acfe_form(array(
            'name' => 'form-step-2'
        ));
    
    // form-step-2 was submitted
    }elseif(acfe_is_form_success('form-step-2')){
    
        // final success message!
        echo 'Success!';
    
    }

    You’ll find more examples of integration if you need here.

    @vy-name Unfortunately the code you submitted doesn’t use ACFE Form code and hooks. I don’t think it will work with the native ACF Form either. That’s kinda the problem with AI solutions which sometimes just invent non-existing code.

    Hope it helps!

    Have a nice day!

    Regards.

    @hwk-fr Many many thanks for such a quick response to this! Wow!

    You saved me several hours of trial-and-error. I agree, many of these AI solutions have been hit-and-miss for me too – BTW, I did not know that these AI LLMs invent code along the way. Damn, that is very untrustworthy, to say the least. Thank you for the warning.

    @sstaples99 sorry if my reply to your query put you to unwanted work. Thanks to @hwk-fr reply above, we are both saved from an avoidable adventure.

    @hwk-fr , BTW, considering this point and more and more of us are creating increasingly large forms with multiple ACF fields, would you kindly consider bringing in this feature of Multi-page (multi-Tab or multi-stage) module for your Forms module UI? Perhaps in the next few releases, if possible? While the code you highlighted above is easy for developers, it is a challenge for non-developers (just designers) like some of us.

    Thanks in advance.

    • This reply was modified 9 months, 4 weeks ago by vy name.
    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Yeah the problem with LLM like Chat GPT or Brave AI is that they are general purpose agents, and basically lack of context. For such specific & specialized tasks as coding, I would recommend to try Github Copilot which is trained for code and thus is way more efficient, as it can also read of the code of your current project (so it has actual context).

    Regarding the multi-step form feature request, this will probably come one day but it might take some time as I know users will want an highly customized experience.

    Some may prefer tabs on top, some at the bottom, some may prefer breadcrumbs, some may prefer to validate & submit each steps individually, some will want ajax, some will want to save and display the last step the user filled before finishing if he left the form and come back later etc… Developers will also want to configure/customize every single text displayed (tabs, breadcrumbs etc…).

    The task itself might seems easy at first sight, since you can already do it with code. But the scope of ACF Extended obliges me to think about all possible implementations, and make all options available via code and via the UI.

    The development cycle of such features often goes this way: first implementation giving all necessary tools for developers, and then later a more “WYSIWYG” experience via an UI, for users which aren’t very technical.

    If you don’t want to bother with code at the moment, I would recommend to use a specialized front-end form plugin with an UI. There’s a lot of solutions out there.

    I hope this answers your questions.

    Thanks!

    Regards.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Forms – Is it possible to create multi page forms’ is closed to new replies.