Home Forums Plugin Support WP User Frontend (Free Version) Feeding variables into the custom forms?

This topic is: resolved

This topic contains 4 replies, has 2 voices, and was last updated by  James 5 years, 5 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #8876

    James
    Participant
    Post count: 3

    Hello,
    I have recently purchased this plugin and it's great, it's doing exactly what I need of it, so thank you very much for that.

    There is however a problem on my site which has nothing to do with WPUF but I was wondering if I could use WPUF to work around it.

    I've got a review system on the site and it's not that great, it's causing many problems and I want to find an alternative. I have come up with an idea using WPUF but it's dependant on a few things.

    So the idea actually came from another member of the WP forum and I'm hoping I can do it with WPUF. I want to create a form in WPUF and call it “Review Form” and in there have a number of dropdowns to select your score, and a textarea for optional comments. This would create posts to a custom post type called “Reviews”. This form would then display at the end of each “normal” post, that requires the review, and I'd do a custom query to get all submitted reviews linked to that post.

    This final part is the bit I'm struggling with. I'd need to somehow link these review posts to the parent post. I was thinking of maybe doing this by having a hidden field on the form which has an identifier so that I can query that in order to get the relevant review posts. I could maybe do this by adding a custom field of “review_id”, create a variable of the main post name or ID and feed that into the review_id custom field. This way, all posts made on this review will have a review_id value which equals the main post title (or ID to make it a bit more secure), then I can custom query that to display all the relevant posts.

    Could this be done in any way with WPUF? Or is there maybe another way to achieve this?

    Thank you, and apologies for the lengthy post.

    #8877

    Tareq Hasan
    Keymaster
    Post count: 2831

    You've to use action hook, take a look at this example.
    http://docs.wedevs.com/using-action-hook-field/

    #8879

    James
    Participant
    Post count: 3

    Thank you so much for this!

    #8921

    James
    Participant
    Post count: 3

    Okay, so this is working fine but I am having trouble getting the parent post ID into the value of the input in the function.

    Do you know how the best way to do this would be? Someone suggested putting $post->ID where the function is being called but I can't find where the function is being called.

    function chalet_review_id_hook($form_id, $post_id, $form_settings, $parentPostID) {
       global $parentPostID;
       $value = '';
    
       if ($post_id) {
          $value = get_post_meta($post_id, 'chalet_review_id', true);
       }
       ?>
    
       <div class="wpuf-label">
          <label>Hidden Chalet Review ID</label>
       </div>
    
       <div class="wpuf-fields">
          <input type="text" name="chalet_review_id" value="<?php echo esc_attr($parentPostID); ?>">
       </div>
       
       <?php
    }
    
    add_action('chalet_review_id', 'chalet_review_id_hook', 10, 3);
    
    function update_my_brand_new_hook($post_id) {
       if (isset($_POST['chalet_review_id'])) {
          update_post_meta($post_id, 'chalet_review_id', $_POST['chalet_review_id']);
       }
    }
    
    add_action('wpuf_add_post_after_insert', 'update_my_brand_new_hook');
    add_action('wpuf_edit_post_after_update', 'update_my_brand_new_hook');

    The $parentPostID is the variable containing the parent post ID.

    Thank you.

    #8988

    James
    Participant
    Post count: 3

    Apologies for multi-post but I managed to get this to work with:

    global $wp_query;
     $parentID = $wp_query->post->ID;

    At the top of the function. Just leaving this here if anyone else needs it.

    Thank you.

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Feeding variables into the custom forms?’ is closed to new replies.