Skip to content

Instantly share code, notes, and snippets.

@robincornett
Created December 30, 2019 16:56
Show Gist options
  • Save robincornett/7e8d26ca58b457ffd128d6ecb7ddfe29 to your computer and use it in GitHub Desktop.
Save robincornett/7e8d26ca58b457ffd128d6ecb7ddfe29 to your computer and use it in GitHub Desktop.
Set up a Gravity Form (in this case, form ID 1) to be sent from one user to another, by repurposing the "save and continue" button.
<?php
add_filter( 'gform_savecontinue_link_1', 'prefix_savecontinue_form_id_1', 10, 2 );
/**
* Maybe remove the "save and continue" button from Gravity Form ID 1.
* Checks to see if the "save and continue" token is present--
* if no, the button will render, otherwise not.
*
* @param string $save_button
* @param object $form
* @return string
*/
function prefix_savecontinue_form_id_1( $save_button, $form ) {
if ( prefix_does_token_exist() ) {
return '';
}
return $save_button;
}
add_filter( 'gform_submit_button_1', 'prefix_submit_form_id_1', 10, 2 );
/**
* Maybe remove the "submit" button from Gravity Form ID 1.
* Checks to see if the "save and continue" token is present--
* if yes, the submit button will render, otherwise not.
*
* @param string $button
* @param object $form
* @return string
*/
function prefix_submit_form_id_1( $button, $form ) {
if ( ! prefix_does_token_exist() ) {
return '';
}
return $button;
}
/**
* Check to see if the second user is viewing the form (based on whether the Gravity Forms token is present).
*
* @return boolean
*/
function prefix_does_token_exist() {
return (bool) filter_input( INPUT_GET, 'gf_token', FILTER_SANITIZE_STRING );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment