Skip to content

Instantly share code, notes, and snippets.

@maarten00
Last active June 1, 2016 23:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maarten00/e8adeb69dc212be3634a to your computer and use it in GitHub Desktop.
Save maarten00/e8adeb69dc212be3634a to your computer and use it in GitHub Desktop.
Gravity forms referrer url fix
function populate_posts($form){
foreach($form['fields'] as &$field){
if($field['defaultValue'] != '{referer}')
continue;
//Check referrer field, if exists and HTTP referrer not set, try to fill it manually
if($field['defaultValue'] == '{referer}' && ! isset($_SERVER['HTTP_REFERER']))
{
$field['defaultValue'] = _getReferrerUrl();
continue;
}
}
return $form;
}
function _getReferrerUrl()
{
$url = 'Referrer niet beschikbaar';
if(isset($_GET['occ_id']))
$url = get_option('home') . '/occasion/' . $_GET['occ_id'];
if(isset($_GET['post_id']))
$url = get_permalink($_GET['post_id']);
return $url;
}
//Add these for each form, where the last number is the form id
add_filter('gform_pre_render_1', 'populate_posts');
add_action("gform_admin_pre_render_1", "populate_posts");
//Occasion version of URL:
<a href="<?= get_option('home') ?>/aanvragen/?occ_id=<?= $o->voertuignr_hexon ?>">Offerte aanvragen</a>
//Post version of URL
<a href="<?=get_option('home')?>/aanvragen/?post_id=<?= $post->ID ?>">Offerte aanvragen</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment