• Hi all

    I am not much of a coder but want to have a way to create [mk_button] with url link to include current query string.

    Something like this:

    example.com/?house=1
    [mk_button url=”/ref/<?house=1>”]

    Does anyone know a simple method to update button reference to include current url query string?

    Thanks in advance!

Viewing 6 replies - 1 through 6 (of 6 total)
  • 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?

    Thread Starter markhuynhmelbourne

    (@markhuynhmelbourne)

    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?

    Thread Starter markhuynhmelbourne

    (@markhuynhmelbourne)

    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/

    Thread Starter markhuynhmelbourne

    (@markhuynhmelbourne)

    Thanks Jacob. I will give your solution a go.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘mk_button with query string’ is closed to new replies.