Question
How can I include a form with default values into new user topics when someone registers on my TWiki site? I've created a form to classify topics in my Main web (using catagories of User, Group and Organization). I'd like to automatically include this form into new users' personal topic when they register.
Here's what I've figured out so far. By reviewing the register script, I see that it generates the new user topic using the register template. So this is a different situation than the example of adding a form to a template topic presented the
TWikiForms docs.
Can I simply add the meta data for the form and fields into the register template?
Well, I guess I may have figured out an anwer for myself here in the course of figuring out what to ask! I suppose I'll give that a try and then report back if it works. If anyone sees I going in the wrong direction or has other suggestions, I'd very much appreciate it!
- TWiki version:
- Web server:
- Server OS:
- Web browser:
- Client OS:
--
LynnwoodBrown - 27 Apr 2002
Answer
The
register script currently reads a default content from a template:
$text = &TWiki::Store::readTemplate( "register" );
You can change that to read from a topic instead (this is actually a more flexible approach):
( $meta, $text ) = &TWiki::Store::readTopic( $TWiki::mainWebname, "NewUserTemplate" );
--
PeterThoeny - 28 Apr 2002
Peter - Thanks for that tip and yes, it seems much more flexible to store the template in an easily modified topic. I will give this a try and report back here on result.
Later... OK, I created the "NewUserTemplate" topic in the main web and added the form with default data selected. I changed the register script as suggested above. I then registered a new user and everything went smoothly, except the form was not included in the new user topic. I went back and double checked that I had included the form in the template. Could something else in the register script be overwriting the metadata? I'll keep fiddling with it to see what I can figure out.
More info... I check the error log and found this:
[Sun Apr 28 12:27:49 2002] register.pl: Name "main::meta" used only once: possible typo at /home/skyloom/public_html/twiki/bin/register.pl line 158.
I checked the script and line 158 is the one I modified as suggested. Don't know what else to make of it...
--
LynnwoodBrown - 28 Apr 2002
The message in the error log is just a warning (since the script has
-w in its shebang line) - it's not serious, but it's good practice to get rid of warnings. It's happening because the routine above returns two values, and you are only interested in the 2nd one, hence $meta is not used. You can suppress it by writing
$meta = $meta;.
--
RichardDonkin - 28 Apr 2002
So the warning message has nothing to do with the fact that the meta data was not picked up with the NewUserTemplate? I was hoping that the
$meta referred to the form and related data I had added to the default new user template - that was the whole point of this exercise. If the error message doesn't tell us anything, anyone have any other ideas why the register script did include the form with the template?
--
LynnwoodBrown - 29 Apr 2002
The warning points to the problem:
$meta is not used for
saveTopic, make sure that you pass the
$meta from
readTopic.
--
PeterThoeny - 29 Apr 2002
Thanks for the further direction, Peter. I'm afraid I could not figure out how to "pass the
$meta from =readTopic=" from reviewing the script, given my limited knowledge of perl. If you can briefly give further direction, I'd appreciate it. If not, I'll try to find someone with more perl knowledge. In the mean time, the registration is basically working as before so I can wait.
As you mentioned earlier, it seems like a more flexible approach to have scripts like this read from templates that can be easily modified. Is this something worth considering for an upcoming release?
--
LynnwoodBrown - 30 Apr 2002
This is now in
TWikiAlphaRelease, see
Codev.NewUserTemplateTopic.
--
PeterThoeny - 05 May 2002
Excellent! Thanks for carrying through that feature request! BTW, I've implemented the changes outlined in
NewUserTemplateTopic on my own TWiki site and they worked like a charm, completely achieving the result I was working towards with my original question.
--
LynnwoodBrown - 05 May 2002