Viewing 6 reply threads
  • Author
    Posts
    • #5305
      George
      Member

      Hello,

      I created a form in the front-end but it is not saving in the database.

      <?php
      /*
      Title: Test
      Method: POST
      Logged in: true
      Message: Data saved.
      */
      
      piklist('field', array(
          'type' => 'text',
          'scope' => 'post_meta',
          'field' => 'test',
          'label' => __('Test'),
      ));
      
      piklist('field', array(
      	'type' => 'submit',
      	'field' => 'submit',
      	'value' => 'Submit'
      ));
      

      After submission i get this notice:
      Notice: Undefined index: post in \www\w\wp-content\plugins\piklist\includes\class-piklist-form.php on line 3028

      Am i missing something?
      If i replace post_meta with user_meta it saves in the wp_usermeta table.

      The form is in a custom post type post?

      Piklist version 0.9.9.7
      Other plugins: WordPress Helpers.

    • #5313
      kabadabra
      Member

      If you’re saving to a CPT, be sure to add the following to the top of the form….

      /*  
      Title: Test
      Method: post
      Logged in: true
      Message: Data saved.
      */
      
      /******* This section here is what you require ********/
      // Where to save this form
      piklist('field', array(
      	'type' => 'hidden',
      	'scope' => 'post',
      	'field' => 'post_type',
      	'value' => 'custom_post_type_here'
      	)
      );
      /***************/
      
      piklist('field', array(
          'type' => 'text',
          'scope' => 'post_meta',
          'field' => 'test',
          'label' => __('Test'),
      ));
      
      // Rest of your form boxes....
      
      piklist('field', array(
      	'type' => 'submit',
      	'field' => 'submit',
      	'value' => 'Submit'
      ));
      

      This defines which CPT to save to.

      Hope this helps!

    • #5314
      George
      Member

      Thank you.

      That does save the value, but not for the post from where it was submitted,
      instead it creates a new post (draft) and associates the meta value to it.

      Is it possible to save it for the current post and on resubmission it updates the value?

    • #5322
      kabadabra
      Member

      I might not understand the above correctly, but I’m assuming you want the post to be set to published when created?

      If so, add the following to your code:

      // post_status
      piklist(
      	'field', array(
      		'scope' => 'post',
      		'type'  => 'hidden',
      		'field' => 'post_status',
      		'value' => 'publish'
      	)	
      );
    • #5324
      George
      Member

      I mean the form is on a published post.

      The form has a meta_key “test”, it should check if there is a meta_key “test” associated with the post the form is submitted from, if there is it updates its value, else it add a new row.

    • #5335
      Steve
      Keymaster

      @fbgm– If you want to edit an existing post you’re going to need the post id. Then add this to the end of the form url:
      ?_post[ID]=ID

      So your url would look like this:
      http://mydomain.com/my_form/?_post[ID]=84

      Is that what you are looking for?

    • #5336
      George
      Member

      Yes that’s it.

      Thank you.

Viewing 6 reply threads
  • The topic ‘Saving post meta from front-end not working’ is closed to new replies.