Skip to content

Instantly share code, notes, and snippets.

@joshmoto
Last active December 15, 2015 17:50
Show Gist options
  • Save joshmoto/5299732 to your computer and use it in GitHub Desktop.
Save joshmoto/5299732 to your computer and use it in GitHub Desktop.
functions.php
<?php
//PRE RENDERING FOR ITEM FIELD
add_filter("gform_pre_submission", "product_items");
add_filter("gform_pre_render", "product_items");
// add_filter("gform_admin_pre_render", "product_items");
function product_items($form){
// THIS IS THE PRE RENDER ON FORM #2 CURRENTLY LIVE AND VALIDATES FINE
if($form["id"] == 2) {
$products = get_field('item_information',$post->ID);
$items = array();
foreach($products as $product)
$items[] = array( "text" => $product['order_description'].' <em class="muted">€'.$product['price_euro'].'</em>', "value" => $product['price_euro'] );
foreach($form["fields"] as &$field){
if($field["id"] == 19 ){
$field["choices"] = $items;
$field["label"] = get_the_title($post->ID);
}
}
return $form;
} else if($form["id"] == 3) {
// HI DAVID, THIS THE TEST FORM #3 PRE RENDER BELOW WHICH IS NOT CURRENTLY VALIDATING
$products = get_field('item_information',$post->ID);
$items = array();
foreach($products as $product)
$items[] = array( "text" => $product['order_description'].' <em class="muted">€'.$product['price_euro'].'</em>', "value" => $product['price_euro'] );
foreach($form["fields"] as &$field){
if($field["id"] == 1 ){
$field["choices"] = $items;
}
}
return $form;
} else {
// ALL OTHER FORMS
return $form;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment