Question
I have a TWiki page that lists some instructions on what users have to do to set something up.. they tend to look like this:
Type the following (replacing USER with your username):
cp /user/USER/file.txt /user/USER/new_place
The 'USER' thing gets repeated a lot, and every now and then somebody forgets to replace USER on every single line, and problems occur. I would like to have the users enter their username in some way, and then have the instructions generate dynamically...
What's the best way to do this? I could use a %USER% variable, but I'm not sure how to let the user set it...
Any hints or ideas would be much appreciated.
Environment
--
StanSokorac - 12 Sep 2007
Answer
If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.
This is indeed possible. Basically, it works like this:
- In your TWiki page, have a small HTML form, with the
action attribute pointing to the page itself. Writing <form action="%SCRIPTURL{view}/%WEB%/%TOPIC%"> will do for any topic, and is easier to copypaste for another use case in another topic.
- As
input element for the form, use a simple text input field and name it, for example, user. Add other fields as you like, and don't forget a submit button.
- In the instructions in the same topic, type
%URLPARAM{"user" default="USER"}% whereever you have USER in your instructions (see TWiki04x01.VarURLPARAM for the meaning of the parameters).
The only example I have immediately at hand is unfortunately a bit
complex, but on the good side it shows the potential of the approach:
TWiki.ApacheConfigGenerator accepts quite a bunch of variables and
changes the contents of the textarea accordingly, for easy copypasting by the users.
--
HaraldJoerg - 13 Sep 2007
Excellent, that's exactly what I was trying to do. The "URLPARAM" part is what I was missing, I was trying to get to the field value using FORMFIELD variables, and it wasn't working.
Thanks!
--
StanSokorac - 13 Sep 2007