• Resolved Elliot Taylor

    (@raisonon)


    I have 3 posts I’m looping through and providing the args post_id and CMB2 ID for the custom fields.

    I’m using cmb2_get_metabox_form (via shortcode as per docs) and outputting 3 forms.

    The first form outputs correctly and saves correctly.

    The second and third forms have the same values of the first form and the save functionality is not working.

    I can show my code, but before I was just wondering if anyone has any obvious reasons why looping through cmb2_get_metabox_form to display front end forms for CMB2 fields would cause a problem like this.

    Thanks

    Elliot

Viewing 15 replies - 1 through 15 (of 15 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    My biggest curiosities is if they’re resulting in the same form IDs etc, since you say it populates the same values in all three. Something with the rendering isn’t making them appear as completely separate things.

    Can you check and see if the places for the 2nd and 3rd ones also saved those values from the first one to the database?

    Just throwing some initial ideas out there.

    Yes please, on sharing your configuration.

    Thread Starter Elliot Taylor

    (@raisonon)

    Hi Michael,

    Thanks for the help.

    I’ve outputted the args and they are unique for each site, so I don’t think that is it.

    If I save and it refreshes then the other forms re-populate with the updated data from the first form.

    Code is not too long and have put in gist here: https://gist.github.com/raisonon/bf0c45ce0e1a80695f0b4f23d2e2d0fa

    Screenshot: https://www.dropbox.com/s/zj7tdwaj9pa4ewe/Screenshot%202016-11-23%2017.13.21.png?dl=0

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    can you provide the CMB2 config as well, the one that sets up the metaboxes themselves.

    Same with the ss_list_array() function.

    Thread Starter Elliot Taylor

    (@raisonon)

    Thanks for helping Michael – all found here:

    – cmb2 config: https://gist.github.com/raisonon/d5f8a251dda1583492243846b060d0db
    – sites page: https://gist.github.com/raisonon/bf0c45ce0e1a80695f0b4f23d2e2d0fa

    Much appreciated.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Sorry for being needy :D, but could you provide the ss_list_array() function as well?

    Also thank you for being patient with me with Thanksgiving and all yesterday.

    Thread Starter Elliot Taylor

    (@raisonon)

    Sorry for the delay and hope you had a nice thanks giving!

    Here is the final function you asked for (thanks)

    https://gist.github.com/raisonon/17e57555104ed9e796087418b6fda280

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Haven’t forgotten, just for your info

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Hrmm.

    The posts2posts usage hinders me doing much debugging, even visually, since I don’t know what an end result of the ss_list_array() may look like.

    Reading over my replies from last week, I think my part here was misunderstood: “My biggest curiosities is if they’re resulting in the same form IDs etc, since you say it populates the same values in all three.“.

    For that part, I wasn’t meaning the parts passed into the cmb2_get_metabox_form() function, like I think they were interpreted as. I meant more about the rendered output and the <form ...> tag itself for all 3. Definitely still a case, as it would seem, that it doesn’t know, or know how, to separate submitting to which form and save for.

    Peaking inside cmb2_get_metabox_form(), this may be part of it: $object_id = $object_id ? $object_id : get_the_ID(); In your own code, you have:

    if ( ! isset( $atts['post_id'] ) ) {
    	$atts['post_id'] = $post->ID;
    }
    

    So just to be sure, are you providing a post ID for each metabox instance to post to? Seems like it’s going to pass in all 1 matching post ID value to save to, if not.

    Thread Starter Elliot Taylor

    (@raisonon)

    Yep, each has own id. I’m fairly sure we’re talking about the same id. Some screenshots:

    sshot1: https://www.dropbox.com/s/zf1woswrdbxdbrp/Screenshot%202016-11-29%2010.16.24.png?dl=0
    sshot2: https://www.dropbox.com/s/ougsatctnqgrpek/Screenshot%202016-11-29%2010.16.46.png?dl=0

    I can also see within the form the correct value is set: https://www.dropbox.com/s/x1a8jd2oomf1d0z/Screenshot%202016-11-29%2010.20.02.png?dl=0

    Blimey, I’m already overblown with the support you are providing and feel bad to ask for any more of your time. I’m not sure how much you can see without the code. The site is available online but I think that goes way past what I would expect from you!!

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    At this point, I’m honestly not sure, without tracing my way through the execution with something like XDEBUG and whatnot.

    Thread Starter Elliot Taylor

    (@raisonon)

    Hi Michael,

    Are you able to output two forms with your setup? I think it might be a bug/limitation of cmb2_get_metabox_form().

    I’ve created a self-contained example here:

    https://gist.github.com/raisonon/6e47208763a877cf7a3b6f3360a5c9de

    It still outputs the first form for both. Perhaps you could try with your own metabox_id and object_id to confirm.

    Thanks

    Elliot

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Is this supposed to be a drop-in replacement for the original ss_frontend_form_shortcode() ? Or something else? I’m not quite piecing it all together yet, mentally.

    Thread Starter Elliot Taylor

    (@raisonon)

    Yep, exactly that – just calling the function rather than echo’ing the shortcode.

    I made it self-contained and simpler to demonstrate the issue. Should be able to use that code to replicate (with equivalent p2p types).

    Main thing is outputting multiple front-end forms on same page.

    Ta

    Thread Starter Elliot Taylor

    (@raisonon)

    Just spent some time trying this again. No luck.

    Would appreciate any help. Forget the code previously posted.

    Just trying to output two forms on one page is a problem. Don’t need to loop, just try and have two meta_boxes from two posts on the same page. Every time the forms are all the same.

    Really appreciate any feedback.

    Thanks

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    So I had a little bit of time tonight, and I tried to make a very basic version of what I think is being aimed for.

    Display output:

    <?php
    $boxes = [
    	[
    		'id' => 'metabox1',
    		'p' => 2,
    	],
    	[
    		'id' => 'metabox2',
    		'p'  => 28,
    	],
    	[
    		'id' => 'metabox3',
    		'p'  => 33,
    	],
    ];
    foreach ( $boxes as $box ) {
    	echo cmb2_get_metabox_form( $box['id'], $box['p'] );
    }
    ?>
    

    Configuration:

    <?php
    function multiple_things() {
    
    	$cmb_demo = new_cmb2_box( array(
    		'id'           => 'metabox1',
    		'title'        => esc_html__( 'Metabox 1', 'cmb2' ),
    		'object_types' => array( 'page' ),
    	) );
    
    	$cmb_demo->add_field( array(
    		'name' => esc_html__( 'Test Text Small', 'cmb2' ),
    		'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
    		'id'   => 'textsmall',
    		'type' => 'text_small',
    	) );
    
    	$cmb_demo2 = new_cmb2_box( array(
    		'id'           => 'metabox2',
    		'title'        => esc_html__( 'Metabox 2', 'cmb2' ),
    		'object_types' => array( 'page' ),
    	) );
    
    	$cmb_demo2->add_field( array(
    		'name' => esc_html__( 'Test Text Small', 'cmb2' ),
    		'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
    		'id'   => 'textsmall',
    		'type' => 'text_small',
    	) );
    
    	$cmb_demo3 = new_cmb2_box( array(
    		'id'           => 'metabox3',
    		'title'        => esc_html__( 'Metabox 3', 'cmb2' ),
    		'object_types' => array( 'page' ),
    	) );
    
    	$cmb_demo3->add_field( array(
    		'name' => esc_html__( 'Test Text Small', 'cmb2' ),
    		'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
    		'id'   => 'textsmall',
    		'type' => 'text_small',
    	) );
    }
    add_action( 'cmb2_init', 'multiple_things' );
    

    Screenshot of output: https://cloudup.com/c1YX2Kf7ST1

    The biggest issue I’m experiencing, is that I’d have to submit 3 times to get all of them filled in. However, clicking the save button does actually save for the associated form field. First submit for the first text, second submit for the second, etc. None of them save all the forms.

    Screenshot of the metadata rows: https://cloudup.com/ckqnD1rw8zf

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Multiple Front End Forms’ is closed to new replies.