5. Passing parameters through a survey
Sometimes you need your own parameters to come back together with the results.
For example, let’s say a page with poll on your site is available for signed up and logged in users only and you know internal user_id of the user participating in poll. In this case, you can send this user_id to the poll and it will be returned to your script (or JS function) with poll results. Besides, this parameter will be saved in report on the respondent for viewing in personal account at Simpoll. So you will be able to define to what user received answers belong.
To pass parameters to a survey:
- embed the survey on a page of your site;
- add a hidden field with the parameters on the same page (as a URL-encoded query string);
Example of passing parameters to a survey:
<?php
// Array of parameters to be sent
// to our site after passing the poll.
// It can be formed dynamically, if necessary.
$params_arr = array(
'user_id' => 123,
'user_login' => 'anonymous'
);
// Create URL-coded inquiry line
$params_str = http_build_query($params_arr);
?>
<!—Create a field with inquiry line -->
<input type="hidden" id="simpoll_params" value="<?php echo $params_str; ?>" />
<!—Connect the poll -->
<script type="text/javascript" src="https://simpoll.com/embed/framejs/aa7ca07e"></script>
The hidden field must have the ID simpoll_params.
The survey embed code must come after the hidden field, otherwise the parameters will not be sent.
When the survey is completed, Simpoll sends these parameters with the results to the Result URL (or to the callback function)
Example of what Simpoll sends:
POST:
(
[user_id] => 123
[user_login] => anonymous
[sp_survey_id] => 551
[sp_survey_key] => aa7ca07e
[sp_resp] => Array
(
[id] => 172693
[ip_addr] => 127.0.0.1
[name] => Respondent No.172693
[time_start] => 2011-12-13 13:23:24
[time_end] => 2011-12-13 13:23:45
[time_delta] => 00:00:21
[quiz_passed] => 0
[quiz_percent] => 33
[quiz_correct] => 3
[quiz_wrong] => 2
)
[sp_result] => 1
[sp_answers] => Array
(
[1] => Array
(
[0] => Italy
)
[2] => Array
(
[0] => Pyramids
[1] => Kremlin
[2] => Colosseum
[3] => Eiffel Tower
)
)
)
Other parameters are the same as described in 3.2.
Passing parameters in the survey URL
If you share a direct link instead of embedding the survey, you can still pass parameters in its URL.
Example of a URL with parameters:
https://simpoll.com/run/survey/aa7ca07e?userid=123&userlogin=anonymous
Parameters in the respondent report
All passed parameters are saved with each respondent’s results.
You see them in the right column of the respondent report in your account.