Remove Return Link on Drupal Webform Ajax Confirmations
The 'Go back to the form' link that the Drupal Webform module prints at the bottom of confirmation messages isn't always desirable, especially in cases where a form is submitted by ajax using the Webform Ajax module.
On a recent project, the client desired to remove the 'Go back to the form' link but only on ajax-enabled forms. This behavior can be achieved in the theme layer.
- Copy 'webform-confirmation.tpl.php' into the theme's templates directory
Since the link code is printed by Webform in the 'webform-confirmation.tpl.php' template file, the first step is to find the 'webform-confirmation.tpl.php' file in Webform's module directory (webform/templates/webform-confirmation.tpl.php) and copy this file to the active theme's templates directory.
- Check if the form is ajax-enabled
The TPL file needs modified to check if the form is ajax-enabled:
The first step is to check if the 'webform_ajax' variable is set. If it's not, then the form is not ajax-enabled (so $ajax = 0). If the variable is set, then the next step is to check if ajax is enabled on the form by checking the value of the 'webform_ajax' variable. If webform_ajax = 1, then ajax is enabled (so $ajax = 1). If webform_ajax ≠ 1, then ajax is not enabled (so $ajax = 0).
- Print the link markup only if the form is not ajax-enabled (i.e. $ajax = 0)
Next, the TPL file needs modified to only print the the return link if the form is not ajax enabled:
The TPL file will now check if ajax is enabled before printing the 'Go back to the form' link. If ajax is not enabled, the link will print. If ajax is enabled, then the link will not print.
In this example, the following projects were used:
- Drupal 7.31
- Webform 7.x-4.0-rc5
- Webform Ajax 7.x-1.1
- *Patched with http://drupal.org/files/webform_ajax-webform-4.x-support-2102029.patch
*Webform Ajax 7.x-1.1 requires a patch in order to support Webform 7.x-4.x. Support for Webform 7.x-4.x has been committed to Webform Ajax 7.x-1.x-dev and will be included in the next stable release of Webform Ajax, presumably 7.x-1.2.
The entire TPL file is provided below:
Add new comment