PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

How to get entry ID from current user?

  1. Tobe

    I have a form for users only, and made sure users can only submit the form only once.
    Once the form is submitted, a page is created using the entry ID as part of the title and url.

    How can I :
    1- Auto check if the user have already submitted the form, and if so;
    2- Hide the form and instead get the user's entry ID and add that to a url ({entry-id} ) or else;
    3- Display the form.

    Thanks in advance!

    Posted 11 years ago on Wednesday April 17, 2013 | Permalink
  2. Tobe

    I tried a lot using the is_user_logged_in function, but that only gives a blank screen.....(no error, no styling, just blank screen on all pages) But if I find a solution for that, how do I make my website check the e-mail address of that user and compare it with all the form entries to find a match, and then get the info from thet form entry to use in a text maybe using merge tags?

    Or is it impossible to display some of the user's entries of a form with some additional text instead of the form itself once the user have submitted the form?
    (Or maybe to create a shortcode for that?)

    Who is keen enough to find a solution?
    I would appreciate your input a lot ;-)

    Posted 11 years ago on Thursday April 18, 2013 | Permalink
  3. Tobe

    This is what I got so far.

    Function to make form-ID=2 to create a page instead of post (thanks to Chris):

    add_filter("gform_post_data", "change_post_type", 10, 2);
    function change_post_type($post_data, $form){
        //only change post type on form id 1
        if($form["id"] != 2)
           return $post_data;
        $post_data["post_type"] = "page";
        return $post_data;

    Code in my page.php to determine what to display depending if user is signed in (or not) and if user do have a page created or not:

    <?php if ( is_user_logged_in() ) { ?>
    <?php global $wpdb;
    $user = wp_get_current_user();
    $where = get_posts_by_author_sql( 'page', true, $user->ID );
    $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" );
    if ( $count >= 1 ) { ?>
    // This is what user see if form is submitted, where '{entry-ID}' should be replaced by the user's entry iD
    <h2>Hey <?php echo $current_user->display_name ?>, thank you for submitting the form. Visit your page here:{entry-ID}</h2>
    <?php } else { ?>
    // If user have not submitted a form, user is shown the info below with the form to submit
    <h2>Hey <?php echo $current_user->display_name ?>, Thank you for joining. To create a page please submit the form below:</h2><?php echo do_shortcode('[gravityform id="2" name="Join the movement of Gooders" title="false" description="false"]'); ?>
    <?php } } else { ?>
    // if user is not logged in, user is urged to log in to submit form
    <h2><Please log in to create a page <?php do_action( 'wordpress_social_login' ); ?></h2>
    <?php } ?>

    Question that is left now:
    What code/function should I use to display the user's entry ID (on form 2) into the url on the second option like:{entry-ID} ??

    Posted 11 years ago on Saturday April 20, 2013 | Permalink