- Posts: 7
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
How to add a button at end of a survey to go to an external URL?
- spt01
- Topic Author
- Offline
- New Member
Less
More
11 years 2 months ago #91282
by spt01
How to add a button at end of a survey to go to an external URL? was created by spt01
Hello,
Does anyone know how to add a button at the end of a survey in order to go to an external URL?
I'm trying to change the source code, but was wondering if anyone has done this before.
Basically I'd like to add a "Preview" button next to "Submit" button at the last page of survey, such that when it's clicked, participants will be redirected to an external link (which will show the preview of current survey results in some format that we desire).
Thanks,
Anna
Does anyone know how to add a button at the end of a survey in order to go to an external URL?
I'm trying to change the source code, but was wondering if anyone has done this before.
Basically I'd like to add a "Preview" button next to "Submit" button at the last page of survey, such that when it's clicked, participants will be redirected to an external link (which will show the preview of current survey results in some format that we desire).
Thanks,
Anna
The topic has been locked.
- helper
- Offline
- Senior Member
Less
More
- Posts: 46
- Thank you received: 7
11 years 2 months ago #91283
by helper
Replied by helper on topic How to add a button at end of a survey to go to an external URL?
How is your technical level? If you have some technical expertise, you may want to consider putting in another button in the SurveyRuntimeHelper.php (in Version 2.00+ Build 130116 the buttons start at about line 1074).
The topic has been locked.
- spt01
- Topic Author
- Offline
- New Member
Less
More
- Posts: 7
- Thank you received: 0
11 years 2 months ago #91284
by spt01
Replied by spt01 on topic How to add a button at end of a survey to go to an external URL?
Thanks for your reply.
I've been looking at frontend_helper.php, in the surveymover() function, it makes more sense to me that I should add a button in the last if statement.
I do not see how we can add a button in the SurveyRuntimeHelper.php.
Maybe I'm wrong.
I've been looking at frontend_helper.php, in the surveymover() function, it makes more sense to me that I should add a button in the last if statement.
I do not see how we can add a button in the SurveyRuntimeHelper.php.
Maybe I'm wrong.
The topic has been locked.
- helper
- Offline
- Senior Member
Less
More
- Posts: 46
- Thank you received: 7
11 years 2 months ago - 11 years 2 months ago #91286
by helper
Replied by helper on topic How to add a button at end of a survey to go to an external URL?
Good catch... seems there are actually a couple of methods that end a survey and they all have a little different method. For example, grep/search for the following term:
javascript:document.limesurvey.move.value = 'movesubmit';
You will find this at least three times within the codebase. Another alternative might be to use CSS to change content or append a static button to the existing button (I think that jQuery has a shortcut for this - charlie.griefer.com/blog/2009/09/17/jque...dding-form-elements/ ).
javascript:document.limesurvey.move.value = 'movesubmit';
You will find this at least three times within the codebase. Another alternative might be to use CSS to change content or append a static button to the existing button (I think that jQuery has a shortcut for this - charlie.griefer.com/blog/2009/09/17/jque...dding-form-elements/ ).
Last edit: 11 years 2 months ago by helper.
The topic has been locked.
- holch
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 11757
- Thank you received: 2753
11 years 2 months ago #91287
by holch
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Replied by holch on topic How to add a button at end of a survey to go to an external URL?
Can't you just include something on the end page on template level?
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
The topic has been locked.
- helper
- Offline
- Senior Member
Less
More
- Posts: 46
- Thank you received: 7
11 years 2 months ago #91289
by helper
Replied by helper on topic How to add a button at end of a survey to go to an external URL?
Actually, if you are not concerned about having this link button on the same page as the submit you could put a static HTML button on the end message (Edit survey text messages). That would probably be the least painful
The topic has been locked.
- tpartner
- Away
- LimeSurvey Community Team
Less
More
- Posts: 10633
- Thank you received: 3697
11 years 2 months ago #91314
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic How to add a button at end of a survey to go to an external URL?
A couple of JavaScript solutions...
Assumptions:
- you are using LS 2
- you want the button on the last question page (not the "End" page)
- you want the link opened in a new window
1) If you want to do this for a single survey, set up your survey to use JavaScript and add the following script to the source of one of the questions on the last question page.
2) If you want do do it for several surveys using the same template, add this to the end of template.js:
Assumptions:
- you are using LS 2
- you want the button on the last question page (not the "End" page)
- you want the link opened in a new window
1) If you want to do this for a single survey, set up your survey to use JavaScript and add the following script to the source of one of the questions on the last question page.
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ var buttonText = 'Review Answers'; var url = 'http://someRedirectLink.com'; $('#movesubmitbtn').before('<button id="movereviewbtn" type="button">'+buttonText+'</button>'); $('#movereviewbtn').click(function() { window.open(url, '_blank'); }).button(); }); </script>
2) If you want do do it for several surveys using the same template, add this to the end of template.js:
Code:
$(document).ready(function(){ if($('#movesubmitbtn').length > 0) { var buttonText = 'Review Answers'; var url = 'http://someRedirectLink.com'; $('#movesubmitbtn').before('<button id="movereviewbtn" type="button">'+buttonText+'</button>'); $('#movereviewbtn').click(function() { window.open(url, '_blank'); }).button(); } });
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: spt01
The topic has been locked.
- spt01
- Topic Author
- Offline
- New Member
Less
More
- Posts: 7
- Thank you received: 0
11 years 2 months ago #91345
by spt01
Replied by spt01 on topic How to add a button at end of a survey to go to an external URL?
Hi Tony,
Thanks for your reply.
I've tried (1), it's successful.
What I need is (2) and I've done per your instruction above, i.e., adding the codes at the end of template.js (I am using 'default' template), but nothing changed. Do I need to setup any other things to make it work?
Thanks,
Anna
Thanks for your reply.
I've tried (1), it's successful.
What I need is (2) and I've done per your instruction above, i.e., adding the codes at the end of template.js (I am using 'default' template), but nothing changed. Do I need to setup any other things to make it work?
Thanks,
Anna
The topic has been locked.
- tpartner
- Away
- LimeSurvey Community Team
Less
More
- Posts: 10633
- Thank you received: 3697
11 years 2 months ago #91346
by tpartner
Are you getting any JavaScript errors?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic How to add a button at end of a survey to go to an external URL?
No, that should work as-is. I assume you are working in a copy of the default template - you can't modify the original.Do I need to setup any other things to make it work?
Are you getting any JavaScript errors?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- spt01
- Topic Author
- Offline
- New Member
Less
More
- Posts: 7
- Thank you received: 0
11 years 2 months ago #91354
by spt01
Replied by spt01 on topic How to add a button at end of a survey to go to an external URL?
Hi Tony,
Thank you!!! It works now (after making a copy of the template).
For the external link, do you know if it's possible to pass parameters such as survey ID & participant's token in template.js, for example:
var url = 'http://someRedirectLink.com?sid={SID}&token={TOKEN}';
I've tried using this, not working so far, maybe I have to use different notations.
Thanks,
Anna
Thank you!!! It works now (after making a copy of the template).
For the external link, do you know if it's possible to pass parameters such as survey ID & participant's token in template.js, for example:
var url = 'http://someRedirectLink.com?sid={SID}&token={TOKEN}';
I've tried using this, not working so far, maybe I have to use different notations.
Thanks,
Anna
The topic has been locked.
- spt01
- Topic Author
- Offline
- New Member
Less
More
- Posts: 7
- Thank you received: 0
11 years 2 months ago #91358
by spt01
Replied by spt01 on topic How to add a button at end of a survey to go to an external URL?
Hi,
I think I find the notations:
var url = 'someRedirectLink.com?sid='+$('#sid').val()+'&token='+$('#token').val();
Thanks again for your help! Really appreciate it.
Anna
I think I find the notations:
var url = 'someRedirectLink.com?sid='+$('#sid').val()+'&token='+$('#token').val();
Thanks again for your help! Really appreciate it.
Anna
The topic has been locked.