2

I'm asked to introduce auto-redirect (to the home page) on the confirmation page of WebForm (i.e. when user sends data, he gets on the page saying "Thank you! You submition has been received, etc..." ). And I'm asked to make a redirect after some time having past, let,s say, 10 seconds.

Seems that I have to introduce some js altering but I don't know how to do this properly.

Thank you!

  • I think you have to write the js code only for the page that you get after redirection.. Moreover you may have to write the redirect code from submission page to home page in js – subhojit777 Jan 30 '13 at 11:10
1

Add this code in webform-confirmation.tpl.php

$(document).ready(function() {
  var delay = 10 ;
  var url = "http://google.com";
  function countdown() {
  setTimeout(countdown, 1000) ;
  $('.webform-confirmation').html("Redirecting in "  + delay  + " seconds.");
  delay --;
  if (delay < 0 ) {
  window.location = url ;
  delay = 0 ;
  }
 }
countdown() ;
});
  • I get this error from Firebug: $(document).ready(function() { -- $ is not a function. Why? – DimG Jan 30 '13 at 13:29
  • Well, for some reason there should have been jQuery(...) instead of $(...). Thanks! – DimG Jan 30 '13 at 14:02
  • 1
    You should always wrap you script with (function ($) { // Here is your script })(jQuery); For more information about using JavaScript in Drupal 7: visit drupal.org/node/756722 – Елин Й. Apr 5 '14 at 9:00
0

Well if you are new in drupal I will explain it to you step by step:

  1. first create a file in 'sites/all/themes/yourtheme/js/' called auto_redirection.js and inside of it paste the code above. (if you do not have the js folder just create one!)

  2. create a file in 'sites/all/themes/yourtheme/templates' called webform-confirmation-'form id'.tpl.php without the quotes, optional you can just let it webform-confirmation.tpl.php and it will be applied to all the webforms confirmations.

  3. go to 'sites/all/modules/webform/templates/webform-confirmation.tpl.php' and copy the content of that file and paste it into your own webform-confirmation-'form id'.tpl.php you already created.

3.Inside the file webform-confirmation-'form id'.tpl.php just add this at the end

drupal_add_js(drupal_get_path('theme', 'yourtheme') . '/js/auto_redirection.js');

do not forget to replace 'yourtheme' for the name of your theme or subtheme... and put the php tags for the above code, for some reason I cannot write the php tags here jeje.

Thats all you need hope it helps someone

0

Use this script instead if you want to display a thank you message and the counter in the message.

    var counter = 10;
setInterval(function() {
    counter--;
    if(counter < 0) {
        window.location = 'http://www.google.com';
    } else {
        document.getElementById("count").innerHTML = counter;
         }
}, 1000);​

add a span with id=count at the message to display the counter.

if found the script here: https://stackoverflow.com/a/12498244/3357085

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.