This question about Using an extension: Answered

How to create new wiki page by merging 2 html form entries

I have followed the FAQ to create a html form that fills data into a form correctly.

I would like the name of the new page to be generated automatically my merging a FirstName and SurName entry, rather like the New User Registration form allows.

How can this be done?

My example (so that changes can be illustrated) below, which includes form DataForm and variables FirstName and SurName:
<form action="%SCRIPTURLPATH{edit}%/%WEB%/"> %BR%
Name of the new topic (i.e. !FirstnameSurname): %BR%
<input type="text" name="topic" class="foswikiInputField" size="30" /> %BR%
First Name: %BR%
<input type="text" name="FirstName" class="foswikiInputField" size="15" /> %BR%
Surname: %BR%
<input type="text" name="SurName" class="foswikiInputField" size="15" /> %BR%
<input type="submit" class="foswikiSubmit" value="Create topic" />
<input type="hidden" name="onlywikiname" value="on" />
<input type="hidden" name="formtemplate" value="DataForm" />
<input type="hidden" name="nowysiwyg" value="1" />
<input type="hidden" name="topicparent" value="%TOPIC%" />
</form>


Name of the new topic (i.e. FirstnameSurname):

First Name:

Surname:

At present, the new topic name has to be entered manually.

Answer

Either use javascript (called with onsubmit) to copy data from both fields to a hidden field topic, or use FormPlugin:

%STARTFORM{
name="newtopic"
action="edit"
validate="on"
topic="$FirstName$LastName"
}%
%FORMELEMENT{
name="FirstName"
title="Your first name"
type="text"
size="40"
mandatory="on"
validate="nonempty"
}%
%FORMELEMENT{
name="LastName"
title="Your last name"
type="text"
size="40"
mandatory="on"
validate="nonempty"
}%
<input type="hidden" name="onlywikiname" value="on" />
<input type="hidden" name="formtemplate" value="DataForm" />
<input type="hidden" name="nowysiwyg" value="1" />
<input type="hidden" name="topicparent" value="%TOPIC%" />
%FORMELEMENT{
name="action"
type="submit"
value="Create New Topic"
}%
%ENDFORM%

-- ArthurClemens - 22 Aug 2009

Further Detail

Many thanks. That works.

An additional point for those of you trying to do this: the FormPlugin defaults to the "Main" web, so in order to keep the newly created form within the same web, add an extra line in the STARTFORM section (e.g. on line 4):
web="Whatever_web_name_you_want_ to_create_the_new_page_in"

or write:
topic="%WEB%.$FirstName$LastName"

-- Ugm6Hr - 22 Aug 2009

QuestionForm edit

Subject Using an extension
Extension
Version Foswiki 1.0.6
Status Answered
Topic revision: r5 - 22 Aug 2009, ArthurClemens - This page was cached on 18 Nov 2018 - 00:21.

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