• Resolved Jules Colle

    (@jules-colle)


    Hi,

    great job on the plugin! I am the developer of Conditional Fields for CF7 (https://wordpress.org/plugins/cf7-conditional-fields/) and I would like to make your plugin compatible with mine. After looking at your code for a while I think I have an idea of how to do this, but would quickly like to check with you if you think my approach would be the best one.

    Conditional Fields (CF) uses 3 hidden fields that are propagated right before submit, containing info about the groups that are currently shown and hidden. I see these fields are correctly added to the cf7msm_posted_data cookie so I should be able to get the info from there. However, when I reach the third step (on a 3 step form) the cookie is updated to represent the situation of step 2, and the group-information of step 1 is lost.

    I don’t believe there is a way to access a field from step 1 that was overwritten in step 2 (because it has the same name), right? Cause if there is, that would be awesome. I’m thinking a multidimensional array, containing all hidden fields per step. The obvious place to implement this would be in your plugin instead of mine I believe. Could you let me know what you think about this?

    Otherwise, I will have to come up with a solution that checks if cf7msm_check is set, and then append the cf7msm_posted_data to my hidden fields each time. This would work as long as a user follows the step in a linear fashion (1-2-3), but will likely fail if the user decides to return to a previous step in the process.

    Anyway, I hope you understand the problem, and should you have any suggestions, I would love to hear them!

    Cheers and keep up the great work!

    Jules

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author webheadcoder

    (@webheadllc)

    Hey,

    you got a nice plugin there! I’d like to make our plugins compatible also. Could you give an example of how a user would use both our plugins and what problems they would have as of right now? I’m not sure I’m seeing the issue.

    Thread Starter Jules Colle

    (@jules-colle)

    Hey Webhead,

    thanks for the positive answer 🙂

    Here is an example of both our plugins combined: http://bdwm.be/wpcf7cf/multistep/
    (Note that I have added some tabs to each form to also show you the form code and the conditions that are used. This is not part of my plugin though.)

    Let me first quickly explain how my plugin works:

    1. you can wrap any part of the form in [group group-name][/group] tags, called a group
    2. The contents of each group are hidden by default.
    3. The user can define some conditions that will make the group contents appear.

    This is the basic functionality of the plugin, and all this works fine in combination with your plugin.

    However! There is an extra feature. Namely, the groups can also be used in the email message. For example if in the email body you write: [group-1]TEXT[/group-1], The text “TEXT” will only be visible if group-1 was visible in the form.

    Now I achieve this by adding the hidden groups to a hidden field in the form, so it gets sent with the POST data, and based on this I can figure out which groups should be shown/hidden in the email message. This works for the last step of the form. But not for all the previous steps of the form. So if in Step 1 [group-1] was shown, this data is POSTed to step 2, but after submitting step 2 the information is lost.

    I hope the problem is clear now 🙂

    BTW: Feel free to submit the form on my website, the email message will be shown as output on the page, so you can see the resulting email.

    • This reply was modified 7 years, 1 month ago by Jules Colle.
    • This reply was modified 7 years, 1 month ago by Jules Colle.
    Plugin Author webheadcoder

    (@webheadllc)

    Thanks for the example. I see the problem now. Having a multidimensional array for for each step sounds like a good idea, but I really don’t have the time to make major changes like that. Do you think it could work if i added a couple of hooks in the cf7msm_store_data_steps_filter function? like maybe a filter for $cf7_posted_data right before merging the prev and current data?

    Thread Starter Jules Colle

    (@jules-colle)

    Hey, yeah that might help. I was trying to get it to work now by always adding the cookie to the posted data. But that seems to fail now as well.. At first I thought the last step of the form was submitted like a normal form (so the POST data would be accessible), but when I test it now (after last update), it looks like the last step is submitted and then the form is redirected again, loosing the POST data. Is that right?

    So yeah, a hook/filter might be the only way. I will add one myself to your code to see if it works, and let you know the exact spot where to add it.

    Thread Starter Jules Colle

    (@jules-colle)

    Never mind. Your answer pointed me in the right direction and there is no need for an extra hook.

    I can just use the 'wpcf7_posted_data' filter to update the posted_data before your plugin starts using it. I used a priority of 8 (where you use 9) to achieve this

    if (!function_exists('cf7msm_get')) add_filter( 'wpcf7_posted_data', array($this,'cf7msm_merge_post_with_cookie'), 8, 1 );

    I’m testing this now and will release the update soon. Thanks for the help! And thanks for the great plugin!

    Plugin Author webheadcoder

    (@webheadllc)

    Oh right you can just use cf7’s filter. Glad you got a solution!

    To answer your question about the last step, it submits the data and sends the email the same as a normal form, then redirects to a new URL if the user entered an additional URL (losing the POST data at this time). If the user didn’t enter a URL on the last step it just shows the success message like a normal form.

    Please update this thread when you release. I’d like to try it out. 🙂

    Any news on this?
    I’m interested in this exact issue too.

    Thread Starter Jules Colle

    (@jules-colle)

    yes, this is possible now. topic is resolved

    Can you confirm this works with your plugin version 1.3.1?

    Because I have troubles displaying conditional fields value on step 2 of a 2 step form.

    Here’s the code I’m using (simplified)

    Step1

    
    [group timegroup][group timegroup2][group timegroup3]
    <label>Service time
    [select* time "" "07:00" "08:00" "09:00" "10:00"]</label>
    [/group][/group][/group]
    
    [group smallhours]
    <label>Service time
    [dynamicselect hours "wpcf7_dynamic_select_hours"]</label>
    [/group]
    

    Step 2:

    
    You are booking for this time [timegroup][timegroup2][timegroup3][multifom "time"][/timegroup][/timegroup2][/timegroup3] [smallhours][multiform "hours"][/smallhours]
    
    • This reply was modified 6 years, 11 months ago by banelicious.
Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘making your plugin compatible with Confitional Fields for CF7’ is closed to new replies.