Tags:
create new tag
view all tags

New Topic Form aka "Create Topic"

This form is designed to allow a user to create topics that do not exist, bypassing the warning "oops" screen you get if you use the "Go" box to do it. In addition to this the NewTopicForm also creates wikiwords from regular text, which might also be useful aswell. eg: "some text" entered to the form takes you directly to the edit mode of a topic called "SomeText". Please let me know what you think of this FeatureHack, and make suggestions on how it could be improved.

If you go to the FeatureHack topic you will notice the CreateTopic form near the top of the page, also please not the statement above it that says "Use a WikiName". I believe the code below is a better solution that could replace the CreateTopicForm, due to the limitation it has in requiring the user to use a WikiWord, (its a minor difference however i beleve it is an important one).

Advantage/Disadvantage outline

  • Advantages
    • Allows users quicker access to editing pages that already exist and also topics that have yet to be created.
    • Turns non wiki word topic names into wiki words when the topic is created if possible.
    • may provide useful (if trivial) in a Forum type atmosphere, where the creation of new topics is needed in thread form.
    • Can be used in combination with the comment plugin and other fields to create interesting and flexable results.
  • Know to work with the following Browsers. (If you test with another browser please list it here)
    • Konqueror 3.1.4-6 Red Hat (Using KDE 3.1.4-4 Red Hat)
    • Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040404 Firefox/0.8
    • Safari 1.2.1
    • Mac Explorer 5.2.3.
    • Internet Explorer 6.0 on Microsoft Windows
  • Disadvantages
    • ?
  • Current Limitations
    • there are limitations on the creation of WikiWords from normal text "foo bar" tunes to "FooBar" upon submission but "foo" will turn to "Foo" and "foo123" will turn to "Foo123" and thanks to the newly added wikiwordonly input attribute, a warning is now given.
    • currently only allows for topics to be created that are children of the topic from which the "value=" of parent topic name is set in the form, this means we are limited to the web from which the Submit button is pressed. Eg: trying to submit something like "Sandbox.FooBar" will create a topic called "SandboxFooBar" in the current web because the "." is dropped during conversion.

ALERT! UPDATES:

  • I added the "wikiwordonly" input attribute to the form so now you get a warning if you are about to create an illegal topic name.
  • Thanks to some help from MartinCleaver via TWikiIRC I have added number handeling so topics like "some text 123" gets converted to "SomeText123" this solves one of the issues ThomasWeigert brought up.

-- TravisBarker - 18 May 2004

Note that if you hit "New" with no text entered, you edit the NewTopicForm. Probably not what was intended?

-- ThomasWeigert - 17 May 2004

I believe if you hit "New" with no text entered, you edit whatever topic you are currently in, just as you would if you were to hit the "normal" edit button, that was not intended, but Im not sure how else to handle it, or if it should be handled at all. what do you suggest? if there was a way to test something like 'if value="" return=None' that could be added to the scripts that would be one solution. does anybody have an idea how to do that? Please also note the existing Create Topic form as used on the FeatureHack page (and others) also has the same issue.

-- TB

Simple Form version (proof of concept)

  • Here is the simplest form, it requires the topic entered be in WikiWord format and will error on save if it is not. Note the value="%TOPIC%" causes the parent child relationship to be preserved so the topic created calls the topic from which this button is submitted its mommy smile
 <form name="goform" action="%SCRIPTURLPATH%/edit%SCRIPTSUFFIX%/%INTURLENCODE{"%WEB%/%TOPIC%"}%">
  <table>
   <tr>
    <td>
    <br>
    <input type="text" name="topic" size="12">
    <input type="hidden" name="topicparent" value="%TOPIC%">
    <input type="submit" value=" New Topic " />
    </span>
   </td>
  </tr>
 </table>
</form>

im not including a working version of the code above because it just doesnt work all that well (too many limitations) I have just placed it here so the underlying concept can be seen before we try to understand more complex versions of it.

Advanced Version notes

  • Below is a more advanced version of the New Topic button it does something similar to the TWikiRegistration form in that it changes the value to a WikiWord when you tab away from the text area however it also tries to do this when you submit the button aswell(or whichever is first), this bit is needed incase your cursor doesnt leave the box before you hit the button the words will still get converted, if for some reason a wiki word cannont be created you will be taken to a warning page before the topic is created.
  • This forms works great with most browsers but the code is UGLY however this can be gotten arround by hiding the code in a NewTopicForm topic somewhere (like a plugin?) and then calling it by using an %INCLUDE{}%.
  • In this form value=%TOPIC% was changed to value=%INCLUDINGTOPIC% this allows the form to be used as an INCLUDE in other topics while preserving the parent child relationship that is desirable.
  • If the code looks familiar, it should, most of it was taken directly from TWikiRegistration form for creating WikiWords from TwikiUser names from the First name / Last Name field. this means NewTopicForm also has the same limitation when doing so, eg: "foo bar" turns to "FooBar" but just "foo" will change to "Foo" and allow the creation of a topic that is not a WikiWord. its legal but discouraged, since non wiki words dont get autolinked in topics.
  • In my opinion both the TWikiRegistration form and this NewTopicForm are "broken" somewhat in that regard. maybe we could allow single name registration while appending something like "User" or as CDot suggested on IRC "Person", ofcourse on the NewTopicForm maybe it could prepend something more like "Topic" to create "FooTopic" per example above, maybe "broken" is overly harsh to call the TWikiRegistration form but none the less, I hope you see the point Im trying to make about its limitation.

Advanced Version Code

  • Here is the code from the latest (and i think) the greatest attempt sofar.

  • In an attempt to make this form work with IE: i have added a "language=Javascript1.2" attribute to the form.(wiki words were not being created in IE if the enter key was used to submit rather than using the button.)


<form name="goform" onsubmit="var sIn = this.form.topic.value; var sOut = ''; var chgUpper = true; for ( var i = 0; i < sIn.length; i++ ) { var ch = sIn.charAt( i ); var ch2 = ''; if((ch=='&#224;')||(ch=='&#225;')||(ch=='&#226;')||(ch=='&#227;')||(ch=='&#229;') ) { ch = 'a'; } if( (ch=='&#232;')||(ch=='&#233;')||(ch=='&#234;') ) { ch = 'e'; } if( ch=='&#231;') { ch = 'c'; } if( ch=='&#241;') { ch = 'n'; } if( (ch=='&#242;')||(ch=='&#243;')||(ch=='&#244;') ) { ch = 'o'; } if( ch=='&#228;') { ch = 'a'; ch2 = 'e'; } if( ch=='&#246;') { ch = 'o'; ch2 = 'e'; } if( (ch=='&#249;')||(ch=='&#250;')||(ch=='&#251;') ) { ch = 'o'; } if( ch=='&#252;') { ch = 'u'; ch2 = 'e'; } if( ch=='&#196;') { ch = 'A'; ch2 = 'e'; } if( ch=='&#214;') { ch = 'O'; ch2 = 'e'; } if( ch=='&#220;') { ch = 'U'; ch2 = 'e'; } if( ch=='&#223;') { ch = 's'; ch2 = 's'; } if( ((ch>='a')&&(ch<='z')) || ((ch>='A')&&(ch<='Z')) || ((ch>='0') && (ch<='9')) ) { if( chgUpper ) { ch = ch.toUpperCase(); chgUpper = false; } sOut+=ch; if( ch2!='') { sOut+=ch2; } } else { if( ch==' ' ) { chgUpper = true; } } } this.form.topic.value=sOut;" action="%SCRIPTURLPATH%/edit%SCRIPTSUFFIX%/%INTURLENCODE{"%WEB%/%TOPIC%"}%">
 <table>
  <tr>
   <td>
     <br>
     <input type="submit" value="New" onclick="var sIn = this.form.topic.value; var sOut = ''; var chgUpper = true; for ( var i = 0; i < sIn.length; i++ ) { var ch = sIn.charAt( i ); var ch2 = ''; if((ch=='&#224;')||(ch=='&#225;')||(ch=='&#226;')||(ch=='&#227;')||(ch=='&#229;') ) { ch = 'a'; } if( (ch=='&#232;')||(ch=='&#233;')||(ch=='&#234;') ) { ch = 'e'; } if( ch=='&#231;') { ch = 'c'; } if( ch=='&#241;') { ch = 'n'; } if( (ch=='&#242;')||(ch=='&#243;')||(ch=='&#244;') ) { ch = 'o'; } if( ch=='&#228;') { ch = 'a'; ch2 = 'e'; } if( ch=='&#246;') { ch = 'o'; ch2 = 'e'; } if( (ch=='&#249;')||(ch=='&#250;')||(ch=='&#251;') ) { ch = 'o'; } if( ch=='&#252;') { ch = 'u'; ch2 = 'e'; } if( ch=='&#196;') { ch = 'A'; ch2 = 'e'; } if( ch=='&#214;') { ch = 'O'; ch2 = 'e'; } if( ch=='&#220;') { ch = 'U'; ch2 = 'e'; } if( ch=='&#223;') { ch = 's'; ch2 = 's'; } if( ((ch>='a')&&(ch<='z')) || ((ch>='A')&&(ch<='Z')) || ((ch>='0') && (ch<='9')) ) { if( chgUpper ) { ch = ch.toUpperCase(); chgUpper = false; } sOut+=ch; if( ch2!='') { sOut+=ch2; } } else { if( ch==' ' ) { chgUpper = true; } } } this.form.topic.value=sOut;" />
     <br>
     <input type="text" name="topic" size="10" value="" onchange="var sIn = this.value; var sOut = ''; var chgUpper = true; for ( var i = 0; i < sIn.length; i++ ) { var ch = sIn.charAt( i ); var ch2 = ''; if((ch=='&#224;')||(ch=='&#225;')||(ch=='&#226;')||(ch=='&#227;')||(ch=='&#229;') ) { ch = 'a'; } if( (ch=='&#232;')||(ch=='&#233;')||(ch=='&#234;') ) { ch = 'e'; } if( ch=='&#231;') { ch = 'c'; } if( ch=='&#241;') { ch = 'n'; } if( (ch=='&#242;')||(ch=='&#243;')||(ch=='&#244;') ) { ch = 'o'; } if( ch=='&#228;') { ch = 'a'; ch2 = 'e'; } if( ch=='&#246;') { ch = 'o'; ch2 = 'e'; } if( (ch=='&#249;')||(ch=='&#250;')||(ch=='&#251;') ) { ch = 'o'; } if( ch=='&#252;') { ch = 'u'; ch2 = 'e'; } if( ch=='&#196;') { ch = 'A'; ch2 = 'e'; } if( ch=='&#214;') { ch = 'O'; ch2 = 'e'; } if( ch=='&#220;') { ch = 'U'; ch2 = 'e'; } if( ch=='&#223;') { ch = 's'; ch2 = 's'; } if( ((ch>='a')&&(ch<='z')) || ((ch>='A')&&(ch<='Z')) || ((ch>='0') && (ch<='9')) ) { if( chgUpper ) { ch = ch.toUpperCase(); chgUpper = false; } sOut+=ch; if( ch2!='') { sOut+=ch2; } } else { if( ch==' ' ) { chgUpper = true; } } } this.form.topic.value=sOut;" on="var sIn = this.value; var sOut = ''; var chgUpper = true; for ( var i = 0; i < sIn.length; i++ ) { var ch = sIn.charAt( i ); var ch2 = ''; if((ch=='&#224;')||(ch=='&#225;')||(ch=='&#226;')||(ch=='&#227;')||(ch=='&#229;') ) { ch = 'a'; } if( (ch=='&#232;')||(ch=='&#233;')||(ch=='&#234;') ) { ch = 'e'; } if( ch=='&#231;') { ch = 'c'; } if( ch=='&#241;') { ch = 'n'; } if( (ch=='&#242;')||(ch=='&#243;')||(ch=='&#244;') ) { ch = 'o'; } if( ch=='&#228;') { ch = 'a'; ch2 = 'e'; } if( ch=='&#246;') { ch = 'o'; ch2 = 'e'; } if( (ch=='&#249;')||(ch=='&#250;')||(ch=='&#251;') ) { ch = 'o'; } if( ch=='&#252;') { ch = 'u'; ch2 = 'e'; } if( ch=='&#196;') { ch = 'A'; ch2 = 'e'; } if( ch=='&#214;') { ch = 'O'; ch2 = 'e'; } if( ch=='&#220;') { ch = 'U'; ch2 = 'e'; } if( ch=='&#223;') { ch = 's'; ch2 = 's'; } if( ((ch>='a')&&(ch<='z')) || ((ch>='A')&&(ch<='Z')) || ((ch>='0') && (ch<='9')) ) { if( chgUpper ) { ch = ch.toUpperCase(); chgUpper = false; } sOut+=ch; if( ch2!='') { sOut+=ch2; } } else { if( ch==' ' ) { chgUpper = true; } } } this.form.topic.value=sOut;" language="Javascript1.2" />
     <input type="hidden" name="topicparent" value="%INCLUDINGTOPIC%">
     <input type="hidden" name="onlywikiname" value="on" />
    </span>
   </td>
  </tr>
 </table>
</form>

Example for testing.

  • HERE is the latest working version as shown verbatim directly above, Ive put the working example in the Sandbox so topics won't be created in the Codev web by mistake, feel free to test it all you like.

Install/Usage instructions.

  1. Create a new topic called NewTopicForm in your web of choice.
  2. Download and copy/paste the NewTopicForm.txt file attached at the bottom of this page into the NewTopicForm topic on your TWiki Site.
  3. Preview and save the topic.
  4. Use the NewTopicForm in other topics of that web by typing %INCLUDE{NewTopicForm}% into the topic you wish to have the form appear. if you wish to use it in other webs you will have to specify the web in the include like this example: %INCLUDE{TWiki.NewTopicForm}%
  5. Have fun creating new topics and jumping directly into edit mode for any topic typed into your new form!

Page Contributors:

-- TravisBarker - 17 May 2004

-- ThomasWeigert - 17 May 2004

-- ArthurClemens - 18 May 2004

-- MartinCleaver - 19 May 2004

Topic attachments
I Attachment History Action Size Date Who Comment
Texttxt NewTopicForm.txt r2 r1 manage 4.9 K 2004-05-19 - 07:11 TravisBarker now works in IE 6.1
Edit | Attach | Watch | Print version | History: r7 < r6 < r5 < r4 < r3 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r7 - 2004-05-19 - TravisBarker
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.