- Posts: 10099
- Thank you received: 3589
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
run php script on completion of a survey
- ryanam
- Topic Author
- Visitor
13 years 2 months ago #55972
by ryanam
run php script on completion of a survey was created by ryanam
I was wondering if it was possible to run a php (something like survey_end.php) script whenever someone completes a survey.
I know someone who did this back when this was phpsurveyor, but I don't know how they did it, and if it is possible with Lime Surveyor.
Thanks!
I know someone who did this back when this was phpsurveyor, but I don't know how they did it, and if it is possible with Lime Surveyor.
Thanks!
The topic has been locked.
- tpartner
- Away
- LimeSurvey Community Team
Less
More
13 years 2 months ago #55975
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 run php script on completion of a survey
Yes, you can fire a PHP script with a JavaScript/AJAX call. You can use the jQuery .get() function as shorthand for the AJAX calls.
Set up your survey to use JavaScript and place the something like this script in the source of the survey end message. This example will call a file "survey_end.php" in your template folder without passing any data to it.
You can pass some values (for example, name and age) to the PHP file via the GET array like so:
More info on the jQuery .get() function here - api.jquery.com/jQuery.get
Set up your survey to use JavaScript and place the something like this script in the source of the survey end message. This example will call a file "survey_end.php" in your template folder without passing any data to it.
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { $.get('upload/templates/yourTemplateName/survey_end.php'); }); </script>
You can pass some values (for example, name and age) to the PHP file via the GET array like so:
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { $.get('upload/templates/yourTemplateName/survey_end.php', { name: 'John Doe', age: '38' } ); }); </script>
More info on the jQuery .get() function here - api.jquery.com/jQuery.get
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: ryanam
The topic has been locked.
- Mazi
- Offline
- Official LimeSurvey Partner
13 years 2 months ago #56015
by Mazi
Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
Replied by Mazi on topic run php script on completion of a survey
Another approach is to simply use the end URL feature and redirect the user to a certain URL which calls the PHP file.
Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
The following user(s) said Thank You: ryanam
The topic has been locked.
- ryanam
- Topic Author
- Visitor
13 years 2 months ago #56038
by ryanam
Replied by ryanam on topic run php script on completion of a survey
Thanks for the helpful replies. I don't have LimeSurvey installed yet, but hopefully should get that done today now that I know it is possible to do what I want to do.
The end URL feature seems pretty straight forward, but I don't believe I've seen anything about it. Is it something I would easily see once I've got LimeSurvey set up?
The end URL feature seems pretty straight forward, but I don't believe I've seen anything about it. Is it something I would easily see once I've got LimeSurvey set up?
The topic has been locked.
- Mazi
- Offline
- Official LimeSurvey Partner
13 years 2 months ago #56073
by Mazi
Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
Replied by Mazi on topic run php script on completion of a survey
You'll find that at the survey settings, watch ut for "end URL":
docs.limesurvey.org/Creating+a+new+surve...ation_amp_navigation
Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
The following user(s) said Thank You: ryanam
The topic has been locked.
- davyhp
- Offline
- New Member
Less
More
- Posts: 4
- Thank you received: 0
11 years 1 month ago #93821
by davyhp
Replied by davyhp on topic run php script on completion of a survey
Hello,
Digging up an old message, but I'm trying to run a script to automate mailings at the end of a survey and I can't seem to get the JavaScript call my PHP script. I've enabled JavaScripts in Limesurvey, an
... prompts up a message box fine if inserted into the text value of some question for example. It also works fine when using the end URL feature redirection with values (but that solution isn't good enough for me since my URL is too long to fit, with 16 values to pass...)
So I wanted to use the code inside the survey, like mentionned :
... but this has no effect, even simple echoes won't show.
Am I doing something wrong? I'm a LS 2.00+ build 130226 user.
Thanks for reading me.
Regards,
Davy.
Digging up an old message, but I'm trying to run a script to automate mailings at the end of a survey and I can't seem to get the JavaScript call my PHP script. I've enabled JavaScripts in Limesurvey, an
Code:
alert('test');
So I wanted to use the code inside the survey, like mentionned :
Code:
$.get('upload/templates/yourTemplateName/survey_end.php');
Am I doing something wrong? I'm a LS 2.00+ build 130226 user.
Thanks for reading me.
Regards,
Davy.
The topic has been locked.
- tpartner
- Away
- LimeSurvey Community Team
Less
More
- Posts: 10099
- Thank you received: 3589
11 years 1 month ago #93829
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 run php script on completion of a survey
Does that mean yo can't get the JavaScript alert to work from the end message?even simple echoes won't show
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13597
- Thank you received: 2487
11 years 1 month ago #93847
by DenisChenu
Denis
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Replied by DenisChenu on topic run php script on completion of a survey
This one is easy to do too.Mazi wrote: Another approach is to simply use the end URL feature and redirect the user to a certain URL which calls the PHP file.
Denis
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
- davyhp
- Offline
- New Member
Less
More
- Posts: 4
- Thank you received: 0
11 years 1 month ago #93862
by davyhp
Replied by davyhp on topic run php script on completion of a survey
If I use JavaScript or PHP through the "end URL" feature, everything works fine, it's when I add code into the survey elsewhere that it doesn't work.
The topic has been locked.
- davyhp
- Offline
- New Member
Less
More
- Posts: 4
- Thank you received: 0
11 years 1 month ago #93863
by davyhp
Replied by davyhp on topic run php script on completion of a survey
It's easy and works fine, but the size of that end URL textbox is too short for what I want it to share with my PHP script...
The topic has been locked.
- ivanleng
- Offline
- New Member
Less
More
- Posts: 1
- Thank you received: 0
11 years 1 month ago #93866
by ivanleng
Replied by ivanleng on topic run php script on completion of a survey
I need to do the same and use a PHP script at the end to send some stuff to an external web service.
I'm thinking about using PHP Session to store some values so they can be easily retrieved, this way my end URL won't be too long.
I'm thinking about using PHP Session to store some values so they can be easily retrieved, this way my end URL won't be too long.
The topic has been locked.
- davyhp
- Offline
- New Member
Less
More
- Posts: 4
- Thank you received: 0
11 years 4 weeks ago - 11 years 4 weeks ago #94006
by davyhp
PHP Session would solve the backend problem, but I can't get a PHP script running from within the code of a survey question... Where else would I put my sessions' variables?
That was the code submitted by tpartner, which isn't working for me inside a survey. Just JavaScript works fine, but the PHP script doesn't run like it does when I use the end URL feature.
Replied by davyhp on topic run php script on completion of a survey
ivanleng wrote: I need to do the same and use a PHP script at the end to send some stuff to an external web service.
I'm thinking about using PHP Session to store some values so they can be easily retrieved, this way my end URL won't be too long.
PHP Session would solve the backend problem, but I can't get a PHP script running from within the code of a survey question... Where else would I put my sessions' variables?
tpartner wrote: <script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$.get('upload/templates/yourTemplateName/survey_end.php', { name: 'John Doe', age: '38' } );
});
</script>
That was the code submitted by tpartner, which isn't working for me inside a survey. Just JavaScript works fine, but the PHP script doesn't run like it does when I use the end URL feature.
Last edit: 11 years 4 weeks ago by davyhp.
The topic has been locked.