Dear @jugiii
we also try to get the referrer url in a caldera form. Can you post how you solved it?
Thanks in advance for sharing Marc
Thread Starter
jugiii
(@jugiii)
It works through detours. First install the plugin PHP Code for Posts, then create a new snippet with the following code:
<?php
session_start();
if($_SERVER["SERVER_PORT"] == 443 )
$http = "https://";
else
$http = "http://";
if ( !isset( $_SESSION["origURL"] ) )
{
$_SESSION["origURL"] = $_SERVER["HTTP_REFERER"];
}
$var = $_SESSION["origURL"];
add_filter( "caldera_forms_render_get_field", function( $field ) {
if( "fld_3267653" == $field[ "ID" ] ){
$field[ "config" ][ "default" ] = esc_url ( $_SESSION["origURL"] );
}
return $field;
});
return $var;
?>
Then insert the shortcode of this snippet (e.g. [php snippet=4] on the page where the shortcode of the Caldera form is called, e.g. directly above. Then create a hidden field with any label in the form itself.
Then use {summary} to output the contents of the hidden field. Important, otherwise it doesn’t work: copy the ID from the hidden field and paste it into the code. In my example this is the fld_3267653. Then delete the cache in the browser and try it out.
If you want to use cookies instead of sessions please use COOKIE everywhere, e.g. $_COOKIE[“origURL”]