This shortcode included in Contact Form – Dynamic Text Extension returns the current URL of the page the form is on.
[CF7_URL]
This shortcode also includes an optional part attribute where you can choose to get just the scheme (aka protocol e.g., “http” or “https”), host (i.e. the domain name), port (may return blank if using port 80), path, query, or fragment.
Examples
To get just the full, absolute URL, the value of my dynamic field would use this:
CF7_URL
And then the dynamic text form tag would look like this:
[dynamictext inputname "CF7_URL"]
Examples for getting the parts look like these:
[dynamictext inputname "CF7_URL part='host'"]
[dynamictext inputname "CF7_URL part='port'"]
[dynamictext inputname "CF7_URL part='path'"]
[dynamictext inputname "CF7_URL part='query'"]
[dynamictext inputname dtx_pageload "CF7_URL part='fragment'"]
Getting the fragment (also known as “hash” or “anchor” in the URL) is only available when cache compatibility is enabled since the fragment is not sent to the server.
Cache Compatibility
If the HTML of your webpage is being cached, preventing the server from processing the shortcode before displaying the form, then you can enable cache compatibility mode for this form tag.
However, this built-in shortcode is unique in that it does not make an AJAX request. Instead, it simply uses JavaScript to pull the current URL or a part of it.
Demo
Check out these fields in action!
View Source Code
View the current source code for the server-side shortcode or for the client-side JavaScript function.