Viewing 2 reply threads
  • Author
    Posts
    • #9483
      Gary McCann
      Member

      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
      Member

      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

Viewing 2 reply threads
  • The topic ‘Update CPT Front End Form without ?_post[ID]=’ is closed to new replies.