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.

After Submission Action Hook

  1. alicewinthrop
    Member

    Hi there,

    The site I am developing needs two general user profiles: corporate and family. Each has a username and password which will be used by members of their respective groups. They do not want individual registration/login.

    I have set up a blog on the site with role-based access/display so the family see the family category archive and the corporates see the corporate category archive.

    I want the visitors to be able to post to the relevant "blog" so I created two forms and used conditional code in the archive.php to display the correct post entry form according to the category being displayed. All good. Form works well.

    Problem is I want to publish the poster's name on the blog and since they are logged in under a general group profile and not as an individual I can't use the_author and so on.

    I created a name field in the form and am trying to follow the after post submission function docs to pick up the data in that name field and assign it to $uniquename which I then echo in archive.php in the meta section. I can't get it to work. Here's my code:

    in functions.php:

    <?php
    add_action("gform_after_submission_3", "after_submission", 10, 2);
    function after_submission($entry, $form){
        $uniquename = $entry["5"];
    }
    ?>

    in archive.php:

    <h2 class="title"><a href="<?php the_permalink();?>"><?php the_title(); ?></a></h2>
    		        <?php the_excerpt(); ?>
    		        <div class="meta"> <?php echo $uniquename; ?></div>

    Any help much appreciated. Thanks.

    -AW

    Posted 11 years ago on Wednesday March 27, 2013 | Permalink
  2. The problem is that $uniquename is not being returned by your gform_after_submission function, and if it were, it would not be related to the $uniquename used in your archive template.

    Are you using a content template for the posts you create with Gravity Forms? That will be the easiest way to get the poster's name into the content. Another way to do it would be to store the poster's name as a custom field associated with the post, then in your archive.php template, you can pull the name from the postmeta with code like this:

    [php]
    <?php
    // this presumes you are storing the poster's name
    // in a custom field named 'uniquename'
    $uniquename = get_post_meta(get_the_ID(), 'uniquename', true);
    if($uniquename != '') {
      echo "<div class='meta'>" . $uniquename . "</div>";
    }

    This code is in your archive.php template and there is no need to use the gform_after_submission hook. You need to be sure to store the poster's name in a post custom field with a key name of uniquename.

    Posted 11 years ago on Sunday March 31, 2013 | Permalink
  3. alicewinthrop
    Member

    Thank you so much. That worked perfectly.

    Posted 11 years ago on Monday April 1, 2013 | Permalink
  4. You're welcome.

    Posted 11 years ago on Monday April 1, 2013 | Permalink

This topic has been resolved and has been closed to new replies.