How to use gravityview/edit_entry/cancel_link

I am trying to use the GravityView hook ‘gravityview/edit_entry/cancel_link’ to change where the “cancel” button takes someone. The hook is documented here: GravityView: form-buttons.php File Reference

What I want to change is the $back_link but I can’t quite figure out how to do it. Here’s what I have so far but this just crashes the form:

add_action( ‘gravityview/edit_entry/cancel_link’, ‘change_cancel_link’, 10, 3);

function change_cancel_link($back_link, $form, $entry, $view_id){
$link = “MY_URL”;
return $link;
}

Can anyone give me any pointers?

Thanks!

So after some trail and error I figured out the solution and figured I’d post it here in case anyone else is looking for a solution, since there seems to be very little in the way of examples out there on how to use this system. It’s actually a two step process:

Part One: change the link URL:

add_action( ‘gravityview/edit_entry/cancel_link’, ‘change_cancel_link’, 10, 3);

function change_cancel_link(){
$back_link = “MY_URL”;
return $back_link;
}

Part Two: Disable the default property, which is to go back one page in the history:

add_action( ‘gravityview/edit_entry/cancel_onclick’, ‘change_cancel_link_js’, 10, 3);

function change_cancel_link_js(){
return “”;
}

1 Like

Hi @user5e5f0c0318fd3879, please make sure to use add_filter() instead of add_action().

If you have any questions, send us an email at support@gravitykit.com. Thanks!