Shortcode gwp_jwt_link
You can use a shortcode to create a link with a JWT token.
This example shortcode will use the Private key saved in the settings of Form ID 1 (the Form we want to fill with JWT claims), links to the page on your site where the form is embedded and includes the JWT claim ‘text’ filled with a Merge Tag from the form you use this shortcode in.
[gwp_jwt_link form_id='1' form_url='https://yoursite.com/prefill-form/' text='{Text:1}']
The shortcode returns a clean url.
You can also generate a link by using the shortcode like this:
[gwp_jwt_link form_id='1' form_url='https://yoursite.com/prefill-form/' text='{Text:1}']Link text[/gwp_jwt_link]
This will return a html link.
The available shortcode settings are:
- form_id (required): this is the ID of the Form you want to populate with JWT claims.
- form_url: this is the url of the page where the url should point to.
- form_url_postfix: possibility to add your own extra parameters to the url.
- url_param: change the token parameter (default is ‘gwp_token’).
- return_format: ‘url’ (default) or ‘token’, which only returns the token.
- disable_iat: disables the issued at date.
- exp: setting an expiration date to the link (see for more detailed instructions below).
Expiration date
You can set the ‘exp’ claim to configure a expiration date of the token. For filling the expiration claim you can use different date formats, for example:
- mm/dd/yyyy. (e.g. 10/13/2024)
- dd-mm-yyyy. (e.g. 13-10-2024)
- A timestamp value. (e.g. 1729123200)
[gwp_jwt_link form_id='1' form_url='https://yoursite.com/prefill-form/' text='{Text:1}' exp='10/13/2024']Link text[/gwp_jwt_link]
Disable IAT (issued at date)
You can disable the issued at date (iat) in the token by adding disable_iat=true.
[gwp_jwt_link form_id='1' form_url='https://yoursite.com/prefill-form/' text='{Text:1}' disable_iat='true']Link text[/gwp_jwt_link]
Change the url-parameter for the token
To change the generated link to something like https://gravitywp.com/prefill-form/?jwt=…. instead of https://gravitywp.com/prefill-form/?gwp_token=….
[gwp_jwt_link form_id='1' form_url='https://gravitywp.com/prefill-form/' text='{Text:1}' url_param='jwt']Link text[/gwp_jwt_link]
To accept this parameter in all your forms you can add this snippet to your site:
add_filter( 'gwp_prefill_token_url_parameter', function( $default, $form ) {
return 'jwt';
}, 10, 2 );
Or, if you want to change it only for form with id 3 only:
add_filter( 'gwp_prefill_token_url_parameter', function( $default, $form ) {
if ( $form['id'] == 3 ) {
return 'jwt';
}
}, 10, 2 );
Last updated: 17-10-2024