• Resolved Ga Satrya

    (@satrya)


    Hi There,
    Is there a way to customize the draft link? I need to add extra parameter to the url, so currently the URL is like this https://website.com/form/?draft=4nb6dfd29e27, I’d like to change it to https://website.com/form/?draft=4nb6dfd29e27&car_id=12345.

    Thanks!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @satrya

    I hope you’re well today!

    The “draft link” that you shared seems to be a post/page draft so I’m assuming it’s a draft post with a form on it but the form itself is published, right?

    With a &car_id=12345 parameter added, it seems like you are trying to “pre-fill” some form field, is that correct?

    If yes, then it should work out of the box anyway. If you already have “pre-populate” option enabled for a form field and its “Query parameter (optional)” option is set to “car_id” then if you access such link, the form would pick it up.

    But I’m not quite sure if I correctly understood your request. If not, please elaborate (example use scenario could help).

    Kind regards,
    Adam

    Thread Starter Ga Satrya

    (@satrya)

    With a &car_id=12345 parameter added, it seems like you are trying to “pre-fill” some form field, is that correct?

    Yes and also no.

    I mean, yes I need the pre-fill but also I need the car_id because there are some custom data that needs this car_id. I was trying to find any hook or filter, but I can’t find anything.

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @satrya

    I hope you are doing well.

    I am afraid we don’t have a filter for that as far as I can see but we may need a different approach here.

    I escalated this case to our developers so we can verify what would be the best way for you.

    We will keep you posted.
    Best Regards
    Patrick Freitas

    Thread Starter Ga Satrya

    (@satrya)

    Thanks!

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @satrya

    I hope you are doing well.

    Can you test this code?

    <?php 
    
    add_filter( 'forminator_form_save_draft_response', 'wpmudev_get_params_draft_link', 10, 2 );
    function wpmudev_get_params_draft_link( $response, $form_id ) {
    	if( $form_id != 361 ) { //Please change the form ID here
    		return $response;
    	}
    
    	$car_id = '';
    	$request_url = parse_url( wp_get_referer() );
    	parse_str( $request_url[ 'query' ], $path );
    	if( $path[ 'car_id' ] ) {
    		$car_id = $path[ 'car_id' ];
    	}
    	
    	$draft_id = isset( $response['draft_id'] ) ? $response['draft_id'] : '';
    	if( $draft_id && $car_id ) {
    		$replace_text = $response['draft_id'].'&car_id='.$car_id;
    		$response['message'] = str_replace( $response['draft_id'], $replace_text, $response['message'] ); 
    	}
    
    	return $response;
    }

    Best Regards
    Patrick Freitas

    Thread Starter Ga Satrya

    (@satrya)

    It works perfectly, Patrick, thank you so much! And now I can add as many custom data based on this car_id. Thank you once again.

    Plugin Support Zafer – WPMU DEV Support

    (@wpmudevsupport15)

    Hi @satrya,

    We are happy to hear that the issue has been resolved.
    Please let us know if you need further help.

    Kind regards,
    Zafer

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Customize draft link’ is closed to new replies.