Re: redirection on submit
allan harold <[email protected]> Tue, 1 Mar 2005 11:25:11 +0000 (UTC)
| Newsgroups | gmane.comp.apache.mod-survey.general |
|---|---|
| Message-ID | <[email protected]> |
Joel Palmius <joel.palmius <at> miun.se> writes:
>
> Sorry for mail flood, but I couldn't continue working before I knew if
> this worked, which it in fact does. Please find example attached.
>
> // Joel
>
> On Tue, 1 Mar 2005, Joel Palmius wrote:
>
> > Another theoretical possibility which I have not tested is to use a perl
> > snippet to change the CONTINUE parameter of the SURVEY tag.
> >
> > Something like
> >
> > <SURVEY .. CONTINUE="default.html">
> > ..
> > <SUBMIT VISIBLE="no">
> > {|
> > if($session->getValue("SUBMITTED_SOMEVAR") eq 1)
> > {
> > $document->SetOption("CONTINUE","someotherpage.html");
> > }
> >> }
> > </SUBMIT>
> > ..
> > </SURVEY>
> >
> > You might have to experiment a bit with this. All submitted variable values
> > should be available through the session with the names SUBMITTED_[variable
> > name].
> >
> > There might be reasons why this won't work, I'll check when I have time to
> > test it.
> >
> > // Joel
> >
> >
> >
> > On Tue, 1 Mar 2005, Joel Palmius wrote:
> >
> >> That's true, this falls between the different options. There is not
> >> straight out any way to do content routing to a post-survey page.
> >>
> >> For now I think making an external script would be the easiest way to
> >> solve it, but I note the problem in my Todo file and will think about a
> >> better way to solve it.
> >>
> >> // Joel
> >>
> >>
> >> On Mon, 28 Feb 2005, allan harold wrote:
> >>
> >>> I am trying to figure out how to send the survey subject to different
> >>> destinations on submit dependent on their response to an earlier survey
> >>> element.
> >>> What I am finding difficult is how to do this at submit. I can see how
> >>> to do it
> >>> during a survey to route to different pages. But as far as I can see,
> >>> at submit
> >>> you can be directed to only one page.
> >>>
> >>> The only option that I can see is to include a code snippet to set a
> >>> cookie that
> >>> a destination page out side of mod_survey can use for a further
> >>> redirect.
> >>>
> >>> Thanks in advance for any suggestions
> >>>
> >>> regards,
> >>>
> >>> allan
> >>>
> >>> Skickat av allan harold <haroldas <at> mcmaster.ca>
> >>> till survey-discussion
> >>>
> >> Skickat av Joel Palmius <joel.palmius <at> miun.se>
> >> till survey-discussion
> >>
> >>
> > Skickat av Joel Palmius <joel.palmius <at> miun.se>
> > till survey-discussion
> >
>
> <SURVEY TITLE="continue" CONTINUE="http://www.miun.se" REDIRECT="yes">
>
> <TEXT NAME="url" CAPTION="Where to go?" />
>
> <SUBMIT VISIBLE="no">
> {|
> my($url) = $session->getValue("SUBMITTED_url");
> if($url)
> {
> $document->SetOption("CONTINUE",$url);
> }
> |}
> </SUBMIT>
>
> </SURVEY>
>
>
Hi, thanks for the response. I made an attempt at the external script last
night and was able to make it work, it did require mucking about with
Document.pm and Display.pm though.
In Document.pm I added two new parameters: JAVASCRIPT and ONLOAD and set them
to null in sub ParamsFill.
In Display.pm in sub new I added the following code in place of the plain body
tag.
if($doc->GetOption("ONLOAD")) # add an onload to body tag
{
print " <body onload=".$doc->GetOption("ONLOAD").">\n";
}
else {print " <body>\n";}
In sub PrintHead I added the following code so that javascript would be
included in the survey page.
if($doc->GetOption("JAVASCRIPT")) # add a javascript include to the header
{
print " <script language=\"javascript\" type=\"text/javascript\"
src=\"". $doc->GetOption("JAVASCRIPT") . "\" />\n";
}
To be able to have a survey variable to test I split the survey into two pages.
The first page is conventional, and has a <ROUTE CONTINUE="last.survey">.
The second page has the following SURVEY tag:
<SURVEY TITLE="Information and Consent" THEME="msu" CAPTWIDTH="300"
CONTINUE="../sc/test-ca2.pl"
REDIRECT="yes" SUBMITTEXT="Submit" SHOWCLEAR="no"
JAVASCRIPT="../res/js/survey.js" ONLOAD="onl()">
The second page has this section that is manipulated by the javascript,
{$consent$} is the variable set on the first page:
<CUSTOM ESCAPED="no" >
<div id="consent" style="display:none">{$consent$}</div>
<div id="response1" style="display:none"> <p><H3> Thank you for
agreeing to participate in this study.</h3></p>
<p>To confirm your decision to participate in this study, please
click <b>Submit</b></p>
</div>
<div id="response0" style="display:none">
<p><H3>Thank you for your consideration.</h3></p>
<p>To confirm your decision not to participate in this study,
please click <b>Submit</b></p></div>
<p>Otherwise "Page Back" <img src="/res/img/back.bmp"/> and
"Reload" <img src="/res/img/reload.bmp"/> the consent page to change your
decision.</p>
</CUSTOM>
The final bit is the javascript file that was included, in this case survey.js:
function onl() {
if (document.getElementById("consent")) {
setCookie('consent',document.getElementById("consent").
innerHTML,3,"/");
}
if (document.getElementById("consent").innerHTML == '1') {
document.getElementById("response1").style.display = "block";
}
if (document.getElementById("consent").innerHTML == '0') {
document.getElementById("response0").style.display = "block";
}
}
function setCookie(name, value, days, path){
if (!days) days = 1; // default to 1 day if empty
var expdate = new Date();
expdate.setTime(expdate.getTime() + days*24*60*60*1000);
document.cookie= name + "=" + escape(value) +
((days) ? "; expires=" + expdate.toGMTString() : "") +
((path) ? "; path=" + path : "");
}
So the way it works, depending on the choice made in the first page, when the
second page is loaded the function onl() is called which reads the value in the
div tag with the id of "consent". A cookie is then set, and the appropriate
block of text is made visible. When submit is clicked the participant is
directed to the next stage(page) in the experiment and I can read the cookie
and take appropriate action based on the cookie.
Sorry for making this so long, but I think it is easier to understand from the
code than just a description.
Regards,
Allan
Skickat av allan harold <[email protected]>
till survey-discussion