Viewing 16 reply threads
  • Author
    Posts
    • #8307
      LEO
      Participant

      Hello!

      I’m new in piklist.

      And I’m looking for making save progress feature in front-end form, by user. So user only see his data in this form.

      Scenario:
      Form example, we have simple front-end form (example.com/form1) with two text field. User fill up this form and click “save & continue later” button. And user log off. After several days user open this form, edit and click “submit”. After submitted form become not editable for this user.

      What architecture should be for several forms ? So it should be comfortable, because I’m planning to fetch data and make simple analytics.

      Is it possible to develop ? What do you recommend ?

      Thanks so much.

    • #8308
      LEO
      Participant

      So, dear guys, I have implemented form wit have progress and data are saved in scope ‘user’.

      Questions:
      1) Need custom statues for record like draft, on pending, declined, and so on.

      2) I need button in form “Submit for checking”, after pressing on it, record status changed to “on pending” and block any user edit.

      3) Manu user fill up this form. And after saving first time (click button “save” on form), this recording will add to special table in admin panel (like showing posts, pages in wordpress admin) with default status “draft”.

      Thanks a lot.

    • #8311
      Steve
      Keymaster

      @platinumwizard– Sounds like a fun project!

      1) You can set custom statuses when you register your post type >

      2) I recommend you add a button with the necessary JS, the same way you would without Piklist.

      3) When you register a post type, WordPress should automatically create a list table for your post type.

    • #8312
      Steve
      Keymaster

      I just thought of an idea…

      1) Create a separate Piklist FORM for each step, in the /forms/ folder
      2) Save each step as a hidden field in each form. So, when they save the second form, the meta_key “step” is set to “2”
      3) Use a Piklist SUBMIT field as the button.
      4) As you save each form use a query parameter to set which form to load and what then next/previous forms are.

      Hope that helps!

    • #8316
      LEO
      Participant

      Good afternoon, Steve!

      I’m glad to text you and to see your helpful feedback.

      Honestly I’m not good in php and in js, but I’m trying to code this.

      I’ve register new post_type “homework” with several statuses – draft, on pending, on remaking, accepted, declined. Have several forms with several field of different types.

      Till it works.

      My idea to have: multi-page frontend forms with save progress feature.

      Next questions is raised:
      1) if we have saved data in scope “user_meta”, how could we show this data in admin dashboard, or maybe I should use another scope ?

      2) How to save data on each form ?
      and
      3) don’t catch “Use a Piklist SUBMIT field as the button.” ?

      Could you please text very simple example code (for example, for form contained one text field) ?

      4) how could I fetch all saved & submitted data ?

      Thanks so much!

    • #8319
      Steve
      Keymaster

      1) I would save the data as a post not user. Make the user the author of the post and then you will have access to all the WordPress author functions.
      2) look in the folder : add-ons/piklist-demos/parts/forms/ for examples
      3) examples are in the /forms/ folder mentioned in #2
      4) The data is just a normal post. Use the standard WordPress loop to grab the data.

    • #8320
      LEO
      Participant

      Steve, i got it. Thanks.

      I did it.

      For example, I do like in demo form “new post with validation”.
      You know, when I use scope “post_meta”, and user refresh/or relogging to site, data he’ve entered didn’t showed in fields form page. How could I solve it ? What should I add to have multi-paged forms with one button submit?

      Don’t find example with save button, I see only with submit button:
      // Submit button
      piklist(‘field’, array(
      ‘type’ => ‘submit’
      ,’field’ => ‘submit’
      ,’value’ => ‘Submit’
      ));

      Also wanna to have data private, and could be seen only by author, but not other users.

      Scenario:
      Form example, we have simple front-end form (example.com/form1) with two text field. User fill up this form and click “save (for continue later)” button. And user log off. After several days user open this form, check data, edit and click “submit”. After submitted form become not editable for this user, but he could see all forms with fields, blocked for editing.

      I’m using 0.10 beta2 version

    • #8321
      Steve
      Keymaster

      1) to show the current values in a form, get the Post ID and add this parameter to each field:
      'object_id' => $post_id

      2) To have private data check to see if the current user is the author, if it is show the data. This is standard WordPress

      • #8338
        LEO
        Participant

        Steve, good afternoon!

        I got the latest record for user via WP_Query, and also added ‘object_id’ => $post_id for each field in my front-end form.

        And after I press submit button for saving data (like in /forms example), it creates new record for custom type, but not edit current record. What’s wrong with this ?

        Thanks.

    • #8323
      LEO
      Participant

      OK. And how to save fields ?

    • #8326
      Steve
      Keymaster

      The demo form should give you all the info you need to save fields.

    • #8339
      LEO
      Participant

      Steve, good afternoon!

      I have one more questions:

      1) I got the latest record for user via WP_Query, and also added ‘object_id’ => $post_id for each field in my front-end form.

      And after I press submit button for saving data (like in /forms example), it creates new record for custom type, but not edit current record. What’s wrong with this ?

      2) In which section and moment I should generate unique number(for my custom field, like unique ticket number) for new record ?

      Thanks in advance.

      Thanks.

    • #8340
      Steve
      Keymaster

      Sorry for the confusion, but $post_id is not a valid WordPress parameter, you need to set it by passing the actual $post->ID.

      When the user clicks on a post to edit it, and a query parameter in the url with the post id.
      Example: http://www.domain.com/form/?form_id=56

      Then in your form get the form_id query parameter using $_GET, and pass it to $post_id.

    • #8341
      LEO
      Participant

      I did this, Steve.

      Look at this, please:
      I have custom post type:

      
      post_types['my_forms'] = array(
              'labels' => piklist('post_type_labels', 'Forms')
              ,'title' => 'My Forms'
              ,'public' => true
              ,'rewrite' => array(
                      'slug' => 'my_forms'
                  )
              ,'supports' => array(
                  'title'
                  ,'post-formats'
                  )
      
              ,'capability_type' => 'post'
              ,'edit_columns' => array(
                  'title' => 'Forms'
                  , 'status' => 'Status'
                  , 'author' => 'User'
                  )
      
              ,'hide_meta_box' => array(
                  'slug'
                  ,'author'
                  ,'revisions'
                  ,'comments'
                  ,'commentstatus'
                  , 'wpseo_meta'
                  )
      
              ,'status' => array(
      
                  'new' => array(
                      'label' => 'New'
                  )
                     ,'status_one' => array(
                          'label' => 'Status One'
                      )
      
                  ,'accepted' => array(
                          'label' => 'Accepted'
                      )
      
                  ,'declined' => array(
                          'label' => 'Declined'
                      )
                  )
      
              ,'form_step' => array(
                      'step-1' => array(
                          'label' => 'Form 1'
                      ),
      
                      'step-2' => array(
                          'label' => 'Form 2'
                      )
                  )
              );
      
          return $post_types;
      

      I have form code

      
      $current_user = wp_get_current_user();
      
          $args = array(
              'post_type' => 'my_forms'
              , 'author'        =>  $current_user->ID
              , 'orderby'       =>  'post_date'
              , 'order' =>  'DESC'
              ,'posts_per_page' => 1
          );
      
          $the_query = new WP_Query( $args );
      
          $post_id = '';
          while ( $the_query->have_posts() ) :
                  $the_query->the_post();
                  $post_id = get_the_ID();
          endwhile;
      
          echo $post_id;
      
          echo "<h4>Forms 1</h4>";
      
              piklist('field', array(
                      'type' => 'hidden'
                      ,'scope' => 'post'
                      ,'field' => 'post_type'
                      ,'value' => 'my_forms'
              ));
      
              piklist('field', array(
                      'type' => 'hidden'
                      ,'scope' => 'post'
                      ,'field' => 'post_title'
                      ,'value' => 'Form One'
              ));
      
              piklist('field', array(
                     'type' => 'hidden'
                      ,'scope' => 'post'
                      ,'field' => 'post_name'
                      ,'value' => 'form1'
              ));
      
              piklist('field', array(
                      'type' => 'hidden'
                      'scope' => 'post'
                      ,'field' => 'post_status'
                      ,'value' => 'status_one'
                      ,'attributes' => array(
                              'wrapper_class' => 'post_status'
                          ),
                  'object_id' => $post_id
              ));
      
              piklist('field', array(
                      'type' => 'hidden'
                      ,'scope' => 'post_meta'
                      ,'field' => 'form_step'
                      ,'value' => 'step-1'
              ));
      
              piklist('field', array(
                      'type' => 'textarea'
                      ,'scope' => 'post_meta'
                      ,'field' => 'title-form-1'
                      ,'label' => 'Name'
                      ,'attributes' => array(
                          'placeholder' => 'Enter Name'
                          ,'rows' => 3
                          ,'cols' => 50
                          ,'class' => 'large-text',
                          'style' => 'width: 100%',
                          ),
      
                      'object_id' => $post_id
              ));
      
              piklist('field', array(
                      'type' => 'submit'
                      ,'field' => 'submit'
                      ,'value' => 'Save'
                      ,'template' => 'submit'
                      ,'attributes' => array(
                          'class' => 'button button-primary'
                      )
              ));

      1) I can’t catch: if I press button Submit, it creates new record each time. Please, provide me example of code. I don’t understand.

      2) In which section and moment I should generate unique number(for my custom field, like unique ticket number) for new record ?

    • #8342
      LEO
      Participant

      What am I doing wrong ?

      By the way, I wanna develop like mentioned in this topic: https://piklist.com/support/topic/muli-page-frontend-form/

      Thanks in advance.

    • #8346
      Steve
      Keymaster

      Leo– I really think you need to do something like this:

      When the user clicks on a post to edit it, and a query parameter in the url with the post id.
      Example: http://www.domain.com/form/?form_id=56

      Then do something like this in your form code:
      if ( isset( $_GET[‘form_id’] ) ) :

      $post = $_GET[‘form_id’];

      else :

      $post = null;

      endif;

    • #8356
      LEO
      Participant

      Steve, I don’t have URL like http://www.domain.com/form/?form_id=56.

      I see shortcake, so user see form on page like http://www.domain.com/form

      How could user could clicks on a post to edit it ?

      Does nobody know about solution of this case?
      Maybe somebody could write very simple example, using at least 1 text field ? or step plan & guide – what to do and what to edit ?

      Or maybe I should use another framework to develop this flow ? Could you point me to resources and forums, that I should to read or study ?

      Thanks a lot, people!

    • #8357
      Steve
      Keymaster

      The link is not automatic. Add the link yourself to your code.

Viewing 16 reply threads
  • You must be logged in to reply to this topic.