You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Mac Schwarz <mc...@phil.uni-erlangen.de> on 2000/08/18 17:22:37 UTC
XSP form processing
Hi,
I've got a problem building forms with xsp and just can't figure out how
to do it correctly at the moment.
I'm just running in circles I think and need an 'eureka effect'.
We want to build some exercises for a language learning project. One
type of exercises would be a gaptext e.g.
<gaptext>
In this sentence a <gab id="1">word</gap> ist missing. Complete these
two <gap id="2>sentences</gap> with the correct words.</gaptext>
Now I need to build a xsl file to transform the gaptext into a form with
the two gaps as input fields (without the words enclosed with the
<gap>-tags of course) and a submit button below. After submission of the
form it should be evaluated (the words inserted by the students compared
with the corresponding words of the source text above) and the text
shown again with the correct answers filled in the text fields of the
form and the wrong answers displayed as empty text fields for another
attempt. Or a page with congratulations for passing the test :-)
I tested variants of the xsp example and code snippets I found in the
mailing list archives, but without avail. Since I don't know the number
of gaps in the text beforehand I can't define the parameters with
<xsl:param> at the top of the stylesheet. So I think I need xsp. I don't
want to use the GET method also to avoid URL encoded parameters but all
of my experiments working with GET never showed any key-value pairs
after changing the method to POST.
I took a look at the fp taglib also and noticed it's potential for a
great range of but for this particular problem I don't think it's
suitable.
I would be grateful for any example code for form processing with xsp.
Regards,
mac
--
Mac Schwarz / AERIA Projekt / Inst. f. Klassische Archaeologie
e-mail: mac@aeria.phil.uni-erlangen.de / Tel.: 09131-85-24791
FAU Erlangen-Nuernberg / Kochstr.4 / 91054 Erlangen
<http://www.phil.uni-erlangen.de/~p1altar/aeriahome.html>
Re: XSP form processing
Posted by Zvi <th...@ifrance.com>.
just try to do some encoding, like MD5 in hidden values,
so nobody will be able to guess words by looking at the page sorce code.
Zvi
Mac Schwarz wrote:
> Ricardo Rocha wrote:
> >
> > Mac Schwarz wrote:
> >
> > > <gaptext>
> > > In this sentence a <gab id="1">word</gap> ist missing. Complete these
> > > two <gap id="2>sentences</gap> with the correct words.</gaptext>
> >
> > XSLT may be enough (provided I really got it):
> >
> > <xsl:template match="gaptext">
> > <form action="gaptext.xml" method="post">
> > <xsl:apply-templates/>
> > </form>
> > </xsl:template>
> >
> > <xsl:template match="gap">
> > <input name="guess" type="text" size="{string-length(.)}"/>
> > <input name="word" type="hidden" value="{string(.)}"/>
> > </xsl:template>
> >
> > These templates should generate something like:
> >
> > <form action="gaptext.xml" method="post">
> > In this sentence a
> > <input name="word" type="hidden" value="word"/>
> > <input name="guess" type="text" size="4"/>
> > ist missing. Complete these two
> > <input name="word" type="hidden" value="sentences"/>
> > <input name="guess" type="text" size="9"/>
> > with the correct words.
> > </form>
> >
> > so that "gaptext.xml" (presumably an XSP page) can process
> > the request examining the multivalued parameters "word" and
> > "guess":
> >
> > . . .
> > <xsp:page xmlns:request="http:www.apache.org/1999/XSP/Request">
> > <page>
> > <xsp:logic>
> > String[] words = request.getParameterValues("word");
> > String[] guesses = request.getParameterValues("guess");
> >
> > int i;
> > for (i = 0; i < words.length; i++) {
> > if (!words[i].equals(guesses[i])) {
> > break;
> > }
> > }
> >
> > if (i == words.length) {
> > <p>Hey! You're a genius!!</p>
> > } else {
> > <p>Try again... asshole!</p>
> > }
> > </xsp:logic>
> > </page>
> > </xsp:page>
> > . . .
> >
>
> Thanks, but no one would be an asshole and all would be geniuses :-)
> Just a look in the pagesource for the hidden input fields.
>
> I'd like to have a simple xml file like
>
> ---------------------------------------
> <?xml version="1.0" ?>
>
> <?cocoon-process type="xslt"?>
>
> <?xml-stylesheet href="xsp.xsl" type="text/xsl"?>
>
> <page>
>
> <parameters/>
> <gaptext>
> In diesem Satz fehlt ein <gap id="1">Wort</gap>.
> In diesem Satz fehlt ein <gap id="2">anderes</gap> Wort.
> </gaptext>
> </page>
> ---------------------------------------
>
> The exercises will be written by our teachers so I don't want any logic
> in the file (besides of the logic of the execises if there's any).
>
> And I want to process this file with an xsl stylesheet (and later with a
> xsp stylesheet and the a xsl stylesheet to seperate logic and style like
> the xsp page/page-xsp/page-html example for cocoon). The stylesheet
> should create a <form action="gaptext.xml" method="POST"><input
> type="text" name="{@id}/> tagset for the gaps distinguished by the gap
> id's.
>
> If the page is called the first time I've got no parameter values and
> the form with empty textfields is generated. If the form is submittet my
> stylesheet should extract the request parameters (the gap id) and it's
> values (the text typed by the student) and compare it with the text
> inside the gap tags with the corresponding gap id. If they match the
> text field of the form should be filled with the correct text. If they
> don't match the text field should be emty for the next try. If all words
> were filled correctly in the gap fields the next exercise should be
> called.
>
> This may sound complicated it's a task you have often. If you want to
> sign up to a new service on the internet you have to fill a form with
> the username, desired password, your name and maybe a email adress. If
> the username is already taken you will get the same form with your name
> and email adress in the text fields of the form but an empty username
> field. If all fields are filled correctly you'll get a 'thank you' page.
>
> Maybe I should go for a walk in the park to flee the sound of
> jackhammers in the next room and hopefully getting a idea how to achive
> this.
>
> mac
>
> --
> Mac Schwarz / AERIA Projekt / Inst. f. Klassische Archaeologie
> e-mail: mac@aeria.phil.uni-erlangen.de / Tel.: 09131-85-24791
> FAU Erlangen-Nuernberg / Kochstr.4 / 91054 Erlangen
> <http://www.phil.uni-erlangen.de/~p1altar/aeriahome.html>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: cocoon-users-help@xml.apache.org
Re: XSP form processing
Posted by Mac Schwarz <mc...@phil.uni-erlangen.de>.
Ricardo Rocha wrote:
>
> Mac Schwarz wrote:
>
> > <gaptext>
> > In this sentence a <gab id="1">word</gap> ist missing. Complete these
> > two <gap id="2>sentences</gap> with the correct words.</gaptext>
>
> XSLT may be enough (provided I really got it):
>
> <xsl:template match="gaptext">
> <form action="gaptext.xml" method="post">
> <xsl:apply-templates/>
> </form>
> </xsl:template>
>
> <xsl:template match="gap">
> <input name="guess" type="text" size="{string-length(.)}"/>
> <input name="word" type="hidden" value="{string(.)}"/>
> </xsl:template>
>
> These templates should generate something like:
>
> <form action="gaptext.xml" method="post">
> In this sentence a
> <input name="word" type="hidden" value="word"/>
> <input name="guess" type="text" size="4"/>
> ist missing. Complete these two
> <input name="word" type="hidden" value="sentences"/>
> <input name="guess" type="text" size="9"/>
> with the correct words.
> </form>
>
> so that "gaptext.xml" (presumably an XSP page) can process
> the request examining the multivalued parameters "word" and
> "guess":
>
> . . .
> <xsp:page xmlns:request="http:www.apache.org/1999/XSP/Request">
> <page>
> <xsp:logic>
> String[] words = request.getParameterValues("word");
> String[] guesses = request.getParameterValues("guess");
>
> int i;
> for (i = 0; i < words.length; i++) {
> if (!words[i].equals(guesses[i])) {
> break;
> }
> }
>
> if (i == words.length) {
> <p>Hey! You're a genius!!</p>
> } else {
> <p>Try again... asshole!</p>
> }
> </xsp:logic>
> </page>
> </xsp:page>
> . . .
>
Thanks, but no one would be an asshole and all would be geniuses :-)
Just a look in the pagesource for the hidden input fields.
I'd like to have a simple xml file like
---------------------------------------
<?xml version="1.0" ?>
<?cocoon-process type="xslt"?>
<?xml-stylesheet href="xsp.xsl" type="text/xsl"?>
<page>
<parameters/>
<gaptext>
In diesem Satz fehlt ein <gap id="1">Wort</gap>.
In diesem Satz fehlt ein <gap id="2">anderes</gap> Wort.
</gaptext>
</page>
---------------------------------------
The exercises will be written by our teachers so I don't want any logic
in the file (besides of the logic of the execises if there's any).
And I want to process this file with an xsl stylesheet (and later with a
xsp stylesheet and the a xsl stylesheet to seperate logic and style like
the xsp page/page-xsp/page-html example for cocoon). The stylesheet
should create a <form action="gaptext.xml" method="POST"><input
type="text" name="{@id}/> tagset for the gaps distinguished by the gap
id's.
If the page is called the first time I've got no parameter values and
the form with empty textfields is generated. If the form is submittet my
stylesheet should extract the request parameters (the gap id) and it's
values (the text typed by the student) and compare it with the text
inside the gap tags with the corresponding gap id. If they match the
text field of the form should be filled with the correct text. If they
don't match the text field should be emty for the next try. If all words
were filled correctly in the gap fields the next exercise should be
called.
This may sound complicated it's a task you have often. If you want to
sign up to a new service on the internet you have to fill a form with
the username, desired password, your name and maybe a email adress. If
the username is already taken you will get the same form with your name
and email adress in the text fields of the form but an empty username
field. If all fields are filled correctly you'll get a 'thank you' page.
Maybe I should go for a walk in the park to flee the sound of
jackhammers in the next room and hopefully getting a idea how to achive
this.
mac
--
Mac Schwarz / AERIA Projekt / Inst. f. Klassische Archaeologie
e-mail: mac@aeria.phil.uni-erlangen.de / Tel.: 09131-85-24791
FAU Erlangen-Nuernberg / Kochstr.4 / 91054 Erlangen
<http://www.phil.uni-erlangen.de/~p1altar/aeriahome.html>
Re: XSP form processing
Posted by Ricardo Rocha <ri...@apache.org>.
Mac Schwarz wrote:
> <gaptext>
> In this sentence a <gab id="1">word</gap> ist missing. Complete these
> two <gap id="2>sentences</gap> with the correct words.</gaptext>
XSLT may be enough (provided I really got it):
<xsl:template match="gaptext">
<form action="gaptext.xml" method="post">
<xsl:apply-templates/>
</form>
</xsl:template>
<xsl:template match="gap">
<input name="guess" type="text" size="{string-length(.)}"/>
<input name="word" type="hidden" value="{string(.)}"/>
</xsl:template>
These templates should generate something like:
<form action="gaptext.xml" method="post">
In this sentence a
<input name="word" type="hidden" value="word"/>
<input name="guess" type="text" size="4"/>
ist missing. Complete these two
<input name="word" type="hidden" value="sentences"/>
<input name="guess" type="text" size="9"/>
with the correct words.
</form>
so that "gaptext.xml" (presumably an XSP page) can process
the request examining the multivalued parameters "word" and
"guess":
. . .
<xsp:page xmlns:request="http:www.apache.org/1999/XSP/Request">
<page>
<xsp:logic>
String[] words = request.getParameterValues("word");
String[] guesses = request.getParameterValues("guess");
int i;
for (i = 0; i < words.length; i++) {
if (!words[i].equals(guesses[i])) {
break;
}
}
if (i == words.length) {
<p>Hey! You're a genius!!</p>
} else {
<p>Try again... asshole!</p>
}
</xsp:logic>
</page>
</xsp:page>
. . .