so you want the current query string from the url in the address and what do you want to do with it exactly?
when you show a button on the page it should grab the house parameter?
Hi Shamai
Yes you are correct, the button should great the all of the query string from the URL. Eg:
URL
example.com/?house=2
Button
[mk_button url=”/ref/?house=2″]
URL
example.com/?site=australia
Button
[mk_button url=”/ref/?site=australia”]
This allows for me to pass these parameters to a form which will then choose the correct display.
Are you using a form plugin or did you make the form yourself?
Are you trying to populate fields in a form?
Hi Shamai
Yes, I am using Gravity Forms plugin. The form allows for capturing of data from the query string and to populate certain fields.
Users come in from external sites and I differentiate this by proving link something like this:
External site 1
example.com/?house=2
External site 2
example.com/?house=5
There is a button on my landing page which I want to direct url to example.com/ref and include the original query string:
example.com/?house=2
example.com/?house=5
The form can then capture parameter house and update the field as required.
This helps me to track on the form where the lead is coming from.
Thanks again for looking into this.
I think you’d be better of capturing the query string in a Cookie, on first visit. And then using the gform_field_value_ filter in Gravity Forms to populate the form.
So you’d have something like
function prefix_remember_query_string() {
if ( isset( $_GET['query_string_to_remember'] ) ) {
setcookie( 'cookie_for_remembering', $_GET['query_string_to_remember'], 30 * DAYS_IN_SECONDS );
}
}
add_action( 'init', 'prefix_remember_query_string' );
function prefix_populate_form_field( $value ) {
if ( isset( $_COOKIE['cookie_for_remembering'] ) ) {
$value = esc_attr( $_COOKIE['cookie_for_remembering'] );
}
return $value;
}
add_filter( 'gform_field_value_your_parameter', 'my_custom_population_function' );
Where gform_field_value_your_parameter is gform_field_value_ then the parameter name as given in Gravity Forms. Read more about that here: https://www.gravityhelp.com/documentation/article/using-dynamic-population/
Thanks Jacob. I will give your solution a go.