Recent Changes - Search:

Cookbook

PmWiki

pmwiki.org

NewPageBoxPlus

Summary: Adds customisable box plus button form for page creation
Status: Stable
Version: 2009-01-29
Prerequisites: PmWiki 2.0
Maintainer: HansB
Categories: Forms CMS

Question

How can I provide a form or box to allow users to create new pages?

Answer

The newpageboxplus.phpΔ script provides a (:newpagebox:) markup which displays a simple box for creating pages:

(:newpagebox:)

(:newpagebox:)

To install, download newpageboxplus.phpΔ, copy into the cookbook folder, and add the following to config.php:

        include_once("$FarmD/cookbook/newpageboxplus.php");

This script can be used as an alternative to NewPageBox and should be installed instead of newpagebox.php.

As the original this alternative script adds markup to place a simple box with button to enter a new page name and submit it, which will take you to the new page ready to edit it.

This script adds additional functionality:

  • The button can be placed either to the right or the left of the input box.
  • The input box can have an initial text displayed inside the box.
  • This can be made to disappear as soon as the box is clicked to enter the new page name, or left as an initial value for a second part of the page name to be entered.
  • The input box and button have additional class stylehooks "inputbox" and "inputbutton" which help integrated styling in a skin (used by Gemini Skin, FixFlow Skin, Triad Skin for instance), i.e. you can use a generic class for both searchbox and newpagebox and other form elements for instance.

Use

Usage is the same as original script, by adding this markup to any wiki page:

(:newpagebox:)

(:newpagebox:)

Possible parameters to use inside the markup:

  • base=Group.PageName -- create page in the same group as Group.PageName (PageName does not need to exist).
  • template=Group.PageTemplateName -- use Group.PageTemplateName as template for new page.
  • value="Create New Page" -- label or value for the inside of the field, which disappears when clicking the box. Default is empty: "".
  • prefix=prefixtext -- prefix will be added in front of name.
  • suffix=suffixtext -- suffix will be added behind name.
  • size=number -- size of input box, default is 30.
  • label="Button Label" -- label for the button, default "Create a new page called:".
  • button=position -- use "left" or "right" to position button (default is "left").
  • focus=true -- adds onfocus and onblur javascript which will make any intial value disappear when clicking on the box. Default is "".
  • save=true or save=1 -- will save the new page directly (without opening it in edit mode), adding any content set with the template option. Default is "". This option is disabld by default, but available for users logged on with 'edit' level. To make it generally available for all users set as local configuration $EnableAutoSave = 1;

Optional config settings

$NewPageProtectedGroups
This is an array of protected groups, for which creation of new pages is prohibited. Default protected groups are 'SiteAdmin' and 'Site'.
$NewPageProtectedGroups[] = 'SpecialGroup';
adds 'SpecialGroup' to array of protected groups.
$NewPageBaseGroup = 'Main';
(example) all new pages will be created in 'Main' group (regardless of any base= parameter setting).
Examples:

New pages will be created in group "Test":

(:newpagebox base=Test.HomePage:)

(:newpagebox base=Test.HomePage:)

Small box with left "Go" button for use in sidebar:

(:newpagebox value="Create New Page" focus=true label=Go button=right
size=16:)

(:newpagebox value="Create New Page" focus=true label=Go button=right size=16:)

Update History

  • 2009-01-29: fixed bug in $NewPageBaseGroup.
  • 2009-01-20: added $NewPageProtectedGroups array and $NewPageBaseGroup variable.
  • 2008-04-27: Fixed save= option so only save=1 or save=true will result in a page save without opening the edit window.
  • 2007-05-02: Changed buggy action to PageUrl, this time properly!
  • 2007-04-17: Changed $PageUrl to $ScriptUrl in form.
  • 2007-01-25: Small optimisation tweak. Removed size default.
  • 2007-01-24a: Optimised code so HTML output is minimised. Hidden fields are only added when needed by the markup.
  • 2007-01-24: Added prefix and suffix optional parameters.
  • 2006-11-26: Added $EnableAutoSave, default false. save=true option is now only available if this variable is set to true or if user is logged on with 'edit' authorisation.
  • 2006-10-28: Added $RecipeInfo
  • 2006-08-05: Added code to strip periods from names, if a base= parameter is specified.
  • 2006-04-28: Added call to SaveAttributes when save=true, which saves link targets.
  • 2006-04-15: Added ctime (page creation time) when new page gets auto saved.
  • 2006-04-10a: Rewritten posting code so new page will appear in RecentChanges, even with save-true option.
  • 2006-04-10: Added Author name when new page gets auto saved.
  • 23 March 06: Changed onfocus/onblur behaviour: Added checking the textbox is still equal to the "value" parameter to stop inadvertant opening of page. Entering a value, leaving the box and returning will have the value still intact and not removed by the second onfocus.
  • 23 March 06: Fixed bug which would open an existing page of form Group.Group if Group was entered and a base group specified. Now the new page will be Base.Group.
  • 20 March 06: Fixed Redirect to new page when save=true.
  • 17 March 06: Fixed bug which allowed overwriting of an existing page by using option save=true. Now it is first checked if the new page exists already, and if it does, it wil open in normal edit mode, and not automatically save a page template as new page content.
  • 27 Feb 06: Added "save" option, which when set to save=true will save the new page without opening it for editing. Combined with the template option new pages with content can be created easily. I use it to create new blog archive and category pages.
  • 4 Jan 06: First release as fourth version of newpagebox.
  • This recipe was last tested on PmWiki version: 2.1.beta17
  • This recipe requires at least PmWiki version: 2

Notes

Comments and Questions

  • Very nice. Would it be possible to include a short descritpion of the parameters into the script itself? So the meaning and function of the parameters could be easily obtained without need for searching for it. You should integrate also the possbility that someone only adds a group name for base. Ok this is a minor one. Klonk January 11, 2006, at 03:07 AM
    Done the documentation. ~'HansB''
  • Would be nice if this could check to make sure the textbox is not left empty (or is still equal to the "value" parameter) - so that inadvertant editing did not happen.
    Fixed now. ~HansB
  • Is it possible to place the newpagebox in the very top line near "recent changes" and "search" ? ~~Peter, 2006-03-02
Assuming you are using the default pmwiki skin, you would need to edit the skin template and css file: In pmwiki.tmpl place <!--markup:(:newpagebox:)--> after <div id='wikihead'> (plus any parameters in the markup), and in pmwiki.css add #wikihead form { float:right }, which will force the forms to stay side by side, and not in two lines. ~HansB
  • If I set save=true, then no author-information is saved. So $LastModifiedby is "". What can I do? flox April 10, 2006, at 04:42 AM
I added author name when new page gets auto saved and changed code so page will appear in RecentChanges even with auto save. ~HansB
  • How complex would it be to tweak this to create a newgroupbox, where the base and the entered value are turned around? I want to have a box where someone can enter the name of a new group, and Group.Base is created, instead of Base.Group. -- JonHaupt
Here it is: see NewGroupBox -- HansB
  • With (:newpagebox .... save=true:) a new created page has 1970-01-01 in $PageCreationDate with:
    # add page variable {$PageCreationDate} in format yyyy-mm-dd
    $FmtPV['$PageCreationDate'] = 'strftime("%Y-%m-%d", $page["ctime"])';
    in config.php. flox April 15, 2006, at 02:57 PM
With save=true the new page did not have ctime set. I updated the script so it now saves also a ctime page creation time stamp when auto saving. -- HansB
As everytime: Thank you very much! flox April 16, 2006, at 03:40 AM
  • If a page is created (save=true), sometimes the page is not listed with (:pagelist:). There seems to be no problem, if I create one without this script. Profiles April 18, 2006, at 12:42 PM
Could you say under which pagelist conditions (parameters) this occurs?

I know, not the best code...

(:pagelist fmt=#galerienormal group=Galerie -2004 -2005 -2006 list=normal -IchHabDichLieb 
-RecentChanges -PageTemplateName -GroupHeader -GroupFooter -GroupAttributes :)

If I create for example the page hallo, it isn't shown there. But it lists "old" pages. Sometimes, if I edit the page again, it is shown in the pagelist. Thanks, flox April 18, 2006, at 03:53 PM

I advise to narrow down the parameters you use, to see when the fault kicks in. You also use -name -name2 etc a lot, and probably want to exclude pages with those words as title. For that it would be better to use name=-name1,-name2 . list=normal should also exclude RecentPages and GroupHeader, GroupFooter GroupAttributes automatically. Finally the reason may be in the fmt=#galerienormal, perhaps you can show it, after trying eliminating other parameters. -- HansB
  • I'm using save=true and template=Xxx. If the template has markup that adds it to a category (e.g. Yyy), then the new page doesn't appear in the category listing (pagelist link=Category.Yyy) unless I edit that page.
    I updated the script, so link targets are saved as well now. -- HansB April 28, 2006, at 03:40 AM
    Hi Hans, that does work. I ran into problems as was using both NewPageBoxPlus and NewGroupBox on the same site - the latter was included second in the config file and still had the old code. The handler for NewGroupBox appears to overwrite the handler for NewPageBoxPlus when included in this order, it took a while to figure this out and get your changed code working for me. Thanks for your work and quick reply!
I changed the handler name in newgroupbox. Thanks for pointing this out! -- HansB May 01, 2006, at 02:38 AM
  • Can you add an option to strip periods (".") from the input? If a visitor uses a period in the input, the specified base group is overridden and the new page is created in a different group, based on the entered string, e.g. "John Q. Public" creates JohnQ.Public (that is, a page called Public in a group called JohnQ). Pico May 17, 2006, at 05:48 PM

Done now. Periods gets stripped if a base= parameter is specified. If no base= is specified the left side will become the group, and the right side of the period the pagename, which lets you create pages in other groups than the current. HansB August 05, 2006, at 01:28 PM

  • Can you add a parameter that puts the link to the new page on the original page right above the markup? It would be great for lists of links. Alex 5th Aug 2006

I think this feature goes a bit beyond the scope of this recipe, it will require rather complex alterations, as the page with the newpagebox markup needs to be changed and saved automatically, apart from creating the new page, which is newpagebox's job. You could perhaps use the (:pagelist:) directive instead. If new pages get created in various groups perhaps set up a template page with a marker on it, like (:comment SpecialMarker:), and use (:pagelist SpecialMarker:) above the newpagebox to list links to all pages with SpecialMarker. HansB

  • Hans, is there a way to use Newpageboxplus with wikiforms? I would like to use a Wikiform that has a button like 'Create new note' or 'create new page' where both the groupname and pagename can be set with variables. Am I making sense here? (hfwang-aug192006)

You can install newpageboxplus and use input form markup like

(:input form :)
(:input hidden action new:)
(:input hidden name "Test.NewPage":)
(:input submit value="Create new page":)
(:input end:)

This will create a button which when clicked will direct to edit a new page named Test.NewPage. You may want to use variables for 'Test' and 'NewPage'. But I am not sure how you apply them, I did not understand your concept for this. Still the input form will use the newpagebox functions. You could also add more hidden fields, for instanc efor a template page:

(:input hidden template "Templates.NewPageTemplate":)

~HansB

Hans, thanks for the swift reply! Let me clarify my wishes a bit.

I am using wikiforms to create a 'project information sheet' page. From this page I would like to be able to 'press a button' to create 'issues', 'notes' etc. all in their own group and manageable with wikiforms. New sub project entries must link to the original project (xxx.0001) and list themself on the ViewTemplate page of the wikiform page. In Short, Projects is the main entry to all information, but issues and notes do have their own page where all of them (thus all projects) are listed as a reguar 'wikilist' entry. HTH! (hfwang-aug192006)

I am sorry but I know nothing about WikiForms, you better ask John Rankin. ~HansB

Possible Solution: I have been tracking for a while the posts of HTH, I have been working in a similar project as well, I think I maybe have found a solution for his application. If you take the following line in the newpageboxplus.php:

" <input class='inputbox newpagetext' name='name' value='{$opt['value']}' size='{$opt['size']}'" . ($opt['focus']=="true" ? $onfocusHTML : "") . "/> \n" .

and then changed for the following :

" <input class='inputbox newpagetext' type='hidden' name='name' value='{$opt['value']}' size='{$opt['size']}'" . ($opt['focus']=="true" ? $onfocusHTML : "") . "/> \n" .

This basically hide the Input Text Box. You will get a imple button linking to the page you want to create in the form:


(:newpagebox base=P{$Name}.Main value=Main label=Go button=left
save=true:) 

(:newpagebox base=PNewPageBoxPlus.Main value=Main label=Go button=left save=true:)


and you yet have the option to specify the template you want to use with with.

Hope that Helps, Marte

  • Could you add a prefix= or suffix= or pattern= option, so that the new page name would have that as part of its name? This isn't the same as base= (which determines the group name); I need something that would affect the page name. For example, if the entered name was NewPage, and the prefix was Foo, then the real new page name would be turned into FooNewPage.
    Kathryn Andersen January 23, 2007, at 07:31 PM
I added prefix and suffix optional parameters to the script. - HansB January 24, 2007, at 05:39 AM


I was looking for a way to have an input select drop down for groups and found this to work in a form (based on the input form markup above:

(:input form :)
(:input hidden action new :)
(:input text name :)
(:input select name="base" value="SomeGroup1" :)
(:input select name="base" value="SomeGroup2" :)
(:input submit value="Add New Page":)
(:input end :)


Seems to work well for me ... so I thought I'd post if for others to see. ~Scott

  • Hans, nice recipe. Could you add an option to skip going to the new page altogether? (even when the page already exists). SteP March 10, 2007, at 05:37 AM
Why would that be desireable, what do you wish to achieve? If not redirected the user has no clue as to what happened (even if nothing happened). - HansB
  • Well the page with (:newpagebox:) also includes (:pagelist group=NewPages:) this way I know when a new pages is created. I have no need to edit the new page, so I want to stay where the creation box is. I like that NewPagesBoxPlus doesn't complain when it can't create a page.
  • I need to change my initial request, could you add an option to go to a "feedback page" --which could also be the current page--and by default is the new page? I would use (:newpagebox goto={$FullName}).
  • NewGroupPage is a very nice recipe, too. I use it to move an existing page set to another group. I like the way that this recipe doesn't complain when some pages already exist. Could you add a "goto" option here too?
  • In both NewPageBoxPlus and NewGroupPage I would also like to hide the text input field, so a user could only press the "Create" button. Is this possible?
  • To move a set of pages from OldGroup to NewGroup I use NewGroupPage as follows: (:pagelist group=NewGroup fmt=#inputcheckboxarray:) creates a csv list of user-selected pages in {$:selected}, then (:newgroupbox base=NewGroup autopages={$:selected}:) copies them to NewGroup, then a ZAP delete action removes the copied pages from OldGroup. SteP
  • Would it be possible to make the newpagebox open a new window when you hit "Create"? -Julie, August 20, 2007 at 07:13 PM
  • How would one go about getting NewPageBoxPlus (or NewGroupBox) to complain if the group or page already exists? It would be nice to be able to turn this function on - with the result being a post to (:messages:) on the same page... overtones99 April 26, 2008, at 03:39 PM
  • Note: BUG(?) - after toiling around with the recipe for a bit, i've noticed that the result in setting save=true and save=false is no different - it redirects the same everytime (to the saved page). rather - i found that setting save=1 and save=0 actually redirected correctly - to the actual page in the former, and to the edit-mode version in the latter... overtones99 April 27, 2008, at 12:53 AM
  • it appears that a creation time is not added to the new page, except under certain circumstances - in my case, the creation times are not being added as a result. so, in my own copy of the recipe, i've moved the ctime instance out of the conditional block, as so, and it seems to work better for my purposes (i.e. i get a correct creation time that's not 31 Dec 1969 everytime...):
                
		if (@$_REQUEST['template'] && PageExists($_REQUEST['template'])) {
			$p = RetrieveAuthPage($_REQUEST['template'], 'read', false, READPAGE_CURRENT);
			if ($p['text'] > '') $new['text'] = $p['text']; 
			$new['author'] = $Author;
			//$new['ctime'] = $Now;   // taking it out of here...
		}       
                $new['ctime'] = $Now; // ... and sticking it here instead...

overtones99 June 02, 2008, at 05:40 AM

  • hi, i would like to copy some PTVs in hidden field to the new created page. Hope you can help me. thank you.

hendrik June 16, 2008, at 05:49 PM

If you want that much, I would recommend you create a NewPage form with Fox, which lets you add all you need. HansB June 17, 2008, at 06:58 AM


Hans, I would like to use this markup as its exactly one of the things I need, however, after I have the people make a new page, how does this markup place a link somewhere? Because if not, the page will never be found. Thanks, Chris September 02, 2010, at 06:33 PM

newpagebox does not place any page link anywhere. This would need to be done manually, or dynamically for instance using a pagelist markup. HansB October 03, 2008, at 09:46 AM

I would suggest a pagelist because it allows you to do some awesome things. Have a look at my Linux group page, that page has only one working line on it:

(:pagelist group=Linux fmt=#titlesummary list=normal:)

In fact, all my group pages are using a single pagelist directive now, it's much easier and saves a lot of work. I use new page box plus and the new pages that are created are automatically included in the appropriate group pages because of the pagelist directive.. I don't have to make any links unless I create a new group. Ian MacGregor


2008-10-02 I'm now using this recipe on my site and it's working perfectly. Thank you for writing this wonderful recipe. Ian MacGregor


2009-01-20 Hans, you may wish to consider changing the first line of HandleNew so that

    $name = stripmagic(@$_REQUEST['name']);

This way, entering "John's dumb test" produces a page called JohnsDumbTest instead of JohnSDumbTest. The reason: single quotes get back-slashed, MakePageName turns the quote into a null, then turns the back-slash into a space, and the resulting space-s is turned into S. The stripmagic removes the back-slash before MakePageName runs. This makes the behaviour consistent with pmwiki: [[John's dumb test]] links to JohnsDumbTest. jr


2010-03-23 If you give a slash "/" in requested Page Titel the page will created in group "Main". To avoid this I've added at line 99 in newpageboxplus.php:

97:	if (isset($NewPageBaseGroup) OR $_REQUEST['base']) {
98:		$name = str_replace(".", "", $name);
99:		$name = str_replace("/", "", $name);
100:		$newpage = MakePageName($base, "$basegroup.$name");	
101:	}

that replace the slash. Peter ---

See Also

User notes +3: If you use, used or reviewed this recipe, you can add your name. The following format is recognized:
* (+) Optional positive comment. Name, date
* (-) Optional negative comment. Name, date

These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.

Edit - History - Print - Recent Changes - Search
Page last modified on June 26, 2010, at 03:19 AM