Last active
October 17, 2023 00:01
-
-
Save estevan-ulian/07b56c0e6dd27666a99914ebcfadea57 to your computer and use it in GitHub Desktop.
Determina 'origin_slug' nos formulários do Gravity Forms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'gform_pre_render', 'populate_referral_url' ); | |
add_filter( 'gform_pre_validation', 'populate_referral_url' ); | |
add_filter( 'gform_pre_submission_filter', 'populate_referral_url' ); | |
add_filter( 'gform_admin_pre_render', 'populate_referral_url' ); | |
function populate_referral_url( $form ){ | |
if ( $form['id'] != 2 && $form['id'] != 3) { | |
return $form; | |
} | |
// get origin URL | |
$origin_url = $_SERVER['HTTP_REFERER']; | |
// parse URL | |
$origin_slug = parse_url($origin_url); | |
// get path of URL and remove bars | |
$path = trim($origin_slug["path"], '/'); | |
foreach($form["fields"] as &$field) | |
if($field->cssClass == 'origin_slug') { | |
$field->defaultValue = $path === '' ? 'home' : $path; | |
} | |
return $form; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment