Hi Bobby. I recommend using the gform_field_value filter:
- For the field you want to store the slug in, check the box to “allow field to be populated dynamically” and give it the parameter name
slug
. - Add this code to the site to grab the permalink, then extract the slug and store it in the field:
add_filter( 'gform_field_value_slug', 'populate_slug' );
function populate_slug( $value ) {
global $post;
GFCommon::log_debug( __METHOD__ . '(): The Post => ' . print_r( $post, true ) );
$permalink = get_permalink( $post );
$parsed_url = parse_url( $permalink );
GFCommon::log_debug( __METHOD__ . '(): The Parsed URL => ' . print_r( $parsed_url, true ) );
return $parsed_url['path'];
}
You can remove the merge tag {embed_url} from the default value for the field. This code will handle populating the field with the slug. Because that is done when the form is first loaded, you can base routing or conditional logic on that field.
Let us know if you need any other assistance.