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.
- 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.
- 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.
- 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