This question about Not sure...: Answered

How do I add a button that creates a topic but also automatically insert a link in the original topic to the new topic

I would like to have 5 "ADD TOPIC" buttons on the page that allow users to create a new topic based on the subject they wrote in the text form field and also insert a link on the original topic page.

I am using this code to display the button and text input:
Please enter the subject for the new topic in the field below
Create topic

Now, how can I have the action of this "Create topic" button inserting a link to the newly created topic right on the same page as the button? This would like this on the topic page :


Here is a list of the existing topic bla bla bla...

[THE CREATE A NEW TOPIC BUTTON]

- Topic A

- Topic B

- Topic C


When the user press on the "Create a new topic", this expands the form with a text input field and a button named "Create topic". The user would write "Topic D" in the field then press the button. This would bring a new created topic named Topic D and add the line : "Topic D" right under "Topic C" with a link to the new topic.

The code would look something like this :

Topic A

Topic B

Topic C

Topic D

Any idea how I could do this?

Thanks!

Simon

-- SimonLessard - 10 Jan 2017

It would be difficult to simultaneously write into the first topic a link to the new topic that you are creating because that would require two separate save actions. However, it would be fairly easy to have a standard search (defined in a view template) that displays the current topic's child-topics. Then add an element to your form that sets the base topic (where the button is displayed) as the parent of your new topic. When you navigated back to the original topic, the search would display your new child topic. Does this make sense?

-- LynnwoodBrown - 10 Jan 2017

Copying your code, you could do something like this that's pretty close to what you're asking for.
Please enter the subject for the new topic in the field below
Create topic

-- LynnwoodBrown - 10 Jan 2017

Hello Lynn,

That is pretty close to what I wanted! The search way is perfectly fine. What if I wanted to have the text entered in the InputField to be passed to the created topic (and stored in a variable?) that I could use

as the title of the page for the new topic? Also, can I have the SEARCH function look for the childs and print on the main page the TITLE of the topic (reading back the variable?) instead of the auto incremented name

of the child topics? Although the wikiname of the topics would still be something like: TestTopic0, TestTopic1, etc...

At last, is there a way to have the results of the search printed in a table with first column=Topic name | second column=date of creation?

Thanks a lot!

-- SimonLessard

Ok, what you need is a Data Form for your topics to be created that includes a field called TopicTitle. Then you would modify the form and search I described above as follows:
%TWISTY{link="%BUTTON{"Create a new topic" icon="add"}%%CLEAR%"
 mode="div"
}%
<form action='%SCRIPTURLPATH{"edit"}%/%WEB%/'> 
<input type="hidden" name="onlywikiname" value="on" >
<input type="hidden" name="t" value="%GMTIME{"$epoch"}%" >
<input type="hidden" name="topicparent" value="%TOPIC%" >
<input type="hidden" name="topic" id="topic" value="TestTopicAUTOINC0" >
%MAKETEXT{"Please enter the subject for the new topic in the field below"}%
| <input class="foswikiInputField" type="text" name="TopicTitle" size="32" placeholder="Enter topic title..." > |%BUTTON{"%MAKETEXT{"Create topic"}%" type="submit"}% %CLEAR% |
</form>
%ENDTWISTY%

%SEARCH{"parent.name = '%TOPIC%'"
  web="%WEB%"
  type="query"
  nonoise="on"
  format="   * [[$web.$topic][$formfield(TopicTitle)]]"
  separator=" $n"
}%

I think that should accomplish what you're after. As an aside, NatSkin (and associated plugins) integrates topic titles "invisibly". E.g. You can define Topic Title values without having the form field and, by default, it displays the topic title in all links to the topic.

-- Main.LynnwoodBrown - 17 Jan 2017 - 15:09

 

QuestionForm edit

Subject Not sure...
Extension
Version Foswiki 1.1.2
Status Answered
Related Topics
Topic revision: r6 - 17 Jan 2017, LynnwoodBrown
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy