Question
The issue is to take the user input for "topic" and prefix it with the current TOPIC and then submit this to create a new topic.
I would also like to choose a templatetopic depending upon the user input for a topic.
<form name="new" action="%SCRIPTURLPATH{save}%/%WEB%/" method="post">
<input type="text" name="topic" size="32" />
<input type="hidden" name="templatetopic" value="TemplateCodeInspectionReportC" />
<input type="hidden" name="topicparent" value=%TOPIC% />
<input type="submit" class="twikiSubmit" value="Submit" />
</form>
What is the best way to procede with this? Would I have to use Javascript or can it be done with a perl plugin module?
Thanks,
Environment
--
NeilMclean - 06 Aug 2008
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.
If you are talking about updating the
templatetopic value based on user input and you don't want to refresh the form, then you'll need a bit of javascript.
--
LynnwoodBrown - 06 Aug 2008
The first part can be done without Javascript or a plugin, but in a roundabout fashion.
Have a form that points to another topic (action="OtherTopic") and passes the user's chosen topic name as a parameter in the URL (for example, you can name the topic text field "t"). You can also set the current topic's name as a parameter, if you want it to be the prefix.
In the OtherTopic, you can then set the topic name to Prefix%URLPARAM{"t"}%
(or %URLPARAM{"prefix"}%%URLPARAM{"t"}% if you set the topic prefix on the previous page).
The downside to this is that it requires two forms, basically, and as you can tell, it's quite cumbersome. But there it is. I'm very much interested in any other suggestions, as this is an issue I ran into in the past.
--
AnthonyCalderon - 06 Aug 2008
Thanks for the reply, I will give the javascript a try as the 'OtherTopic' approach would be too cumbersome in this case. Thanks!
--
NeilMclean - 08 Aug 2008
I had a look at the
NameTopicBasedOnFormFieldContent
topic to do the javascript, which is exactly what I'm trying to do.
I've got this far :
<script>
<!--
function canSubmit(myform) {
myform.action = "%SCRIPTURLPATH{"view"}%/%WEB%/NewForm";
myform.submit();
}
//--></script>
<form name="inform" action="javascript:canSubmit(this)">
| Topic Name: | <input type="text" name="topic" size="70" value="" /> |
| Project Name: | <input name="ProjectName" type="text">|||
| | <input type="submit" value=" Generate Topic"/ > |
<input type="hidden" name="templatetopic" value="DocumentGeneratorTemplate" />
<input type="hidden" name="topicparent" value="%TOPIC%" />
</form>
There is probaly something very obvious to someone what is not quite right. At the moment it calls the function but I cannot get javascript to call the Twiki action.
Any help please?
--
NeilMc - 09 Aug 2008
I have it working now!
See Raw View to check out how its done.
I think it was 'document.inform' that was needed instead of 'this'.
Also if the javascript is not perfect then nothing happens ( it can't run ) which may have been the problem.
Once I got this working, lots more is possible, such as choosing formtemplate and topictemplates from dropdown value selectors, etc...
Hope this helps others, thanks everyone!
--
NeilMc - 09 Aug 2008