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.

Gravity Form Based Auctions

  1. Hello,

    Proving just how amazingly versatile GF is - it took me more time to make dinner tonight than it did to use GF with a custom post type to make an auction / bid system out of WordPress. The current version requires people to enter name / email for validation, but if you want a barebones silent auction tool it does the job quite well.

    Highlights to make it happen:

    • Dynamically populate postID into hidden field via theme functions.php file:
      add_filter("gform_field_value_itemID", "populate_itemID");
      function populate_itemID(){
          global $post;
          $itemID_value = $post->ID;
          return $itemID_value;
      }
    • Add a custom field to the post type called - auction_highbid - and output it to the appropriate template in theme:
      <span id="highbid" style="display: none;"><?php echo get_post_meta($post->ID, "auction_highbid", "true"); ?></span>
    • Although custom validation is not yet implemented as a core feature - a re-purposing of jquery code found in another forum thread does allow me to client-side prevent users from submitting forms with lower than current highbid values:
      jQuery(document).ready(function(){
          highbid = parseFloat(jQuery("#highbid").text());
      
          jQuery(".auction_bid .instruction").empty();
          jQuery(".auction_bid .instruction").append('The current high bid for this item is $' + highbid);
      
          jQuery("input.button").click(
              function(){
                  if(parseFloat(jQuery(".auction_bid input").val()) <= highbid)
                  {
                      jQuery(".auction_bid").addClass("gfield_error");
                      jQuery(".auction_bid .validation_message").remove();
      
                      jQuery(".auction_bid .ginput_container").append("<div class='gfield_description validation_message'>You must bid higher than $" + highbid + ".</div>");
                      return false;
                  }
              }
          );
      });
    • Tap the gform_pre_submission action in functions.php to update the high bid custom field:
      add_action("gform_pre_submission", "pre_submission_handler");
      function pre_submission_handler($form_meta){
          global $_POST;
      
          if($form_meta["id"] != '3'){
              return;
          }
      
          $itemID = $_POST["input_3"];
          $userBid = $_POST["input_1"];
          $userBid = (float)$userBid;
      
          $highBid = get_post_meta($itemID, "auction_highbid", "true");
          $highBid = (float)$highBid;
      
          $file = dirname(__FILE__);
          $file = substr($file, 0, stripos($file, "wp-content") );
      
          require( $file . "/wp-load.php");
      
          if($userBid > $highBid) {
              update_post_meta($itemID, "auction_highbid",  $userBid);
          }
      }

    A couple of questions that come to mind regarding GF functionality as a result of this project. I haven't done any coding with GF in a few months so please forgive me if these questions are repeats - I searched the forum for tags that made sense to me about them first.

    1. Is there a hook / action that would allow me to customize the export feature? When the auction is over I'd like to have more than just the postID of the product. An alternate solution might be to include the post title as an additional hidden field.
    2. Is there a function call I could use from within the admin to find the # of entries a given form currently has submitted? Being able to have a snapshot view for how many bids have been placed on a product from the post type edit screen would be nice.
    3. What are the next big features you're working towards implementing? User registration, payment gateways, custom validation all come to mind as things which would be quite excellent.

    You have a great product and functionality built into GF - but it is getting harder to locate how to do things which turn out to be quite easy. Atleast 50% of the forum threads that I read as I refreshed myself on how to do things mentioned a "very big documentation update coming soon"....starting atleast 7 months back. What is the status of that or has it happened? It took me a while to find the way to call shortcode via template function and have styles properly enqueue'd which would be a fairly standard thing I'd imagine.

    Thanks!
    Jamie

    Posted 13 years ago on Thursday September 23, 2010 | Permalink
  2. The documentation is basically complete, however we have to integrate it into the site. It's built on the WikiMedia platform so we need to integrate that with WordPress. It's still going to be sometime as other Gravity Forms development is taking up our time.

    Which export feature are you referring to? The export entries or forms? I don't believe there are currently hooks for either. However if you need to do some sort of custom export you can copy that portion of the code from the plugin and create your own export functionality from it that could reside in a custom plugin you create yourself using that copied code.

    To output the number of entries for a form you can use this code:

    $summary = RGFormsModel::get_form_counts(2);
    echo "The Form count for Form #2 is: ".$summary['total'].".";

    The 2 in the get_form_count call is the form id.

    We are currently working on pricing field calculations and the PayPal add-on.

    Posted 13 years ago on Thursday September 23, 2010 | Permalink
  3. ZOIKES! I've run into an issue that is somewhat time-sensitive. If someone can suggest a workable alternative I'd be most happy.

    Is there a better / recommended way in gform_pre_submission to evaluate all the entry values for a specific field - auction_bid - where another field matches a specific value - auction_itemID? To be absolutely certain that no same or higher bids have been received.

    The numeric field validation used above allows for concurrent higher than current bid stored in custom field to be accepted at near real-time. If the custom field value - auction_highbid - were 55 and two people submitted values of 60 at or reasonably close to the same time, the validation would accept that their entry is acceptible and post the resulting entry + update the fields. But only one should actually be accepted.

    I cannot use the 'no duplicates' validation b/c I'm using one form for all 30 auction items so a lower identical bid could win a separate item.

    Thanks,
    Jamie

    Posted 13 years ago on Wednesday October 27, 2010 | Permalink