This topic contains 2 replies, has 2 voices, and was last updated by  Steve 5 days, 7 hours ago.

  • Author
    Posts
  • #9483

    Gary McCann
    Participant

    I have a page where I want to embed a front end form. This will be unique to a user and users should only edit their own page/forms.

    Ideally I want to set the CPT post ID.

    When I use the code below with the URL http://../forms/sample/?_post[ID]=364 all works as expected, it updates the existing CPT.

    <?php
    /*
    Title: Post Submit
    Method: post
    Message: Saved
    Logged in: true
    */
    
    // Where to save this form
    piklist('field', array(
      'type' => 'hidden'
      ,'scope' => 'post'
      ,'field' => 'post_type'
      ,'value' => 'cpt1'
    ));
    
    piklist('field', array(
          'type' => 'select'
          ,'field' => 'cpt1_field1'
          ,'label' => 'Field1'
          ,'scope' => 'post_meta'
          ,'attributes' => array(
            'class' => 'text'
          )
         ,'choices' => array(
              '1' => 'Option1',
              '2' => 'Option2',
              '3' => 'Option3',
              '4' => 'Option4'
         )
    
    ));
    
      // Submit button
      piklist('field', array(
        'type' => 'submit'
        ,'field' => 'submit'
        ,'value' => 'Submit'
      ));
    
    ?>

    What I really want is for the form to load when a user visits http://../forms/sample/

    I’ve tried:

    $post = get_post(374);
    setup_postdata( $post );

    but I assume that other code for the form runs before this. Is there a way to set the post id in the code rather than the URL?

  • #9484

    Gary McCann
    Participant

    Solved it. I just cheat and set the global $_Request variable and then use do_shortcode

    .e.g.

    $_Request['_post']['ID'] = 374;
    do_shortcode('[piklist_form form="sample" add_on="sample-plugin"]');
  • #9490

    Steve
    Keymaster

    You could also pass ['_post']['ID'] as a query parameter in the url

You must be logged in to reply to this topic.