Edit Links

Summary: add edit links for editing page sections and PTVs with Fox
Version: 2017-06-16
Prerequisites: pmwiki 2.2.56 and later, Fox. (PHP 5.5 compatible)
Categories: Forms Markup Fox

Questions answered by this recipe

How can I add edit links which will open an edit form to edit a page section or PTVs?

Description

An add-on for form processors like Fox to add edit capabilities

Install in the usual manner by copying to cookbook/ or cookbook/fox/ folder and including in local config file.

This script adds a markup {[foxedit]} which creates an edit link to open a page section for editing with a special edit form. The following parameters can be used within the markup:

{[foxedit section label form=EditFormName]}

  • section is either a page section enclosed with page anchors, or a named page text variable.
  • label (as second parameter) can be an alternative to 'Edit' for the link label.
  • form=EditFormName can be used to specify a custom edit form, which the link will call.
  • tooltip='STRING' or title='STRING' adds link tooltip (HTML <a title='STRING'...).

There are two default edit forms, configurable with setting variables:

  • $FoxEditPTVSectionForm = 'FoxTemplates.EditPTVForm';
  • $FoxEditPageSectionForm = 'FoxTemplates.EditSectionForm';

Please make sure you have these forms installed, or set variables to custom forms you use!
For message editing in FoxForum use FoxTemplates.EditMessageForm and set in your local/Forum.php config file:

$FoxEditPTVSectionForm = 'FoxTemplates.EditMessageForm';

Three page variables are defined which can be used in the edit form:

  • {$EditTarget} - page in which the section or ptv(s) will be updated, usually the calling page. Can be named in the edit link markup.
  • {$EditSection} - anchored section or ptv which will be loaded for editing, named in the edit link markup.
  • {$EditSource} - page which holds the section or ptv to be updated, usually the calling page, and same as the the target page. Can be named in the edit link markup.

A custom markup is included by which an anchored section of form [[#anchor]] .... [[#anchorend]] (note the closing anchor name with an 'end' added) can be treated as a PTV. But note that FoxEdit (version 2008-03-29) will use the section edit form now. This may be reviewed in future.

The form examples shown here have some additional line breaks, in order to preserve the ski layout. Remove as necessary for your wiki page!

Example: FoxTemplates.EditSectionForm: Form to edit anchored sections

(:foxmessages:)
(:if foxpreview:)
!!!$[Preview]: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; %green%[-&ndash;
 $[Changes have not been saved] &ndash;-]
>>frame<<
(:foxdisplay:)
>><<
(:if:)

(:fox editform foxaction=replace put=overwrite  target={$EditTarget}{$EditSection}
 redirect={$EditTarget}{$EditSection}:)
(:foxtemplate "":)(:input default request=1:)
(:input hidden csum 'Section {$EditSection} edited':)
(:if equal {$EditSection} '':)!!!$[Editing page]: &nbsp; %color=#009%{$EditTarget}
(:else:)!!!$[Editing section]: &nbsp; %color=#009%{$EditSection}(:if:)
|| ||(:guibuttons:)||
|| ||(:input textarea id=text name=text style='width:95pct'
 cols=90 rows=12 class=inputtext:) ||
(:input hidden access {$Accesscode}:)(:input hidden accesscode {$AccessCode}:) 
|| ||Author: (:input text author value='{$Author}' size=30 class=inputtext:)
 &nbsp; (:input submit post $[Save]:) &nbsp; (:input submit preview $[Preview]:)
  &nbsp; (:input submit cancel $[Cancel]:) ||
(:foxend editform:)
(:if foxpreview:)
%green center%[+&ndash; $[Changes have not been saved] &ndash;+]

Example:FoxTemplates.EditPTVForm: Form to edit a single PTV

(:foxmessages:)
(:if foxpreview:)
!!!$[Preview]: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; %green%[-&ndash;
 $[Changes have not been saved] &ndash;-]
>>frame<<
(:foxdisplay:)
>><<
(:if:)

(:fox editform  ptvtarget={$EditTarget} ptvfields={$EditSection} redirect=1:)
(:foxpreviewtemplate "{$$ptv_{$EditSection}}":)
(:input hidden csum 'Section {$EditSection} edited':)
(:if foxpreview :)(:input default request=1:)(:else:)
(:input default source={$EditSource} :)(:ifend:)
!!!$[Editing PTV]: &nbsp; %color=#009%{$EditSection}
||(:guibuttons:) ||
||(:input textarea id=text name=$:{$EditSection} cols=80 rows=12 class=inputtext:) ||
(:if enabled EnableAccessCode:)
||Enter value {$AccessCode} (:input text access size=3 class=inputtext:)
(:input hidden accesscode {$AccessCode}:)  <- Have you entered the code number? ||
(:if enabled EnablePostCaptchaRequired:)
||Enter value {$Captcha} (:input captcha class=inputtext:)
 <- Have you entered the code number? ||
(:if:)
||Author: (:input text author value='{$Author}' size=30 class=inputtext:) &nbsp;
 (:input submit post '$[Save]':) &nbsp; (:input submit preview $[Preview]:)
 &nbsp; (:input submit cancel '$[Cancel]':) ||
(:foxend editform:)
(:if foxpreview:)
%green center%[+&ndash; $[Changes have not been saved] &ndash;+]

See FoxContacts for an application which uses a custom edit form to edit the fields of a contacts info page.

Notes

Edit Forms with Preview button

If a foxedit link calls an edit form which includes a 'Preview' button, make sure of the following:

  • The form name is 'editform' or 'editform1' 'editform2' etc., or foxedit=1 is added to the fox markup
  • The preview button is named preview, like (:input submit preview 'Preview':)

The form examples on this page have been updated to include Preview, and the FoxForum zip file contains page files in its templates.d folder for ready use.

  • If you are designing a form for editng PTVs, use a (:foxpreviewtemplate "..":) markup and prefix any PTV names for replacement variables with ptv_, like for a PTV name1. But in the input field use name=$:name1 like (:input text name=$:name1:). PmWiki adds a ptv_ prefix for internal use, but we have to add it for the preview template variables in order to catch the input for the preview.

Adding edit links to FoxForum posts

  1. Install FoxEdit
  2. Edit FoxTemplates.FormTemplates and add inside the (:include ... :) markup
    of sections headed comment form and newtopic form
    editlink="Edit" (best before the deletelink= ).
  3. Edit FoxTemplates.DisplayTemplates and add in all sections before
  4. set in your local/Forum.php config file:
$FoxEditPTVSectionForm = 'FoxTemplates.EditMessageForm';
  1. Create FoxTemplates.EditMessageForm with this content:
%red%(:foxmessages:)(:if foxpreview:)
!!!$[Preview]: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; %green%[-&ndash;
 $[Changes have not been saved] &ndash;-]
>>frame<<
(:foxdisplay:)
>><<(:ifend:)
(:fox editform  ptvtarget={$EditTarget} redirect=1 :)
(:input hidden csum 'Section {$EditSection} edited':)
(:foxpreviewtemplate "'''{$$ptv_subject{$EditSection}}'''
 \n----\n\n{$$ptv_message{$EditSection}}":)
(:if foxpreview:)(:input default request=1:)(:else:)
(:input default source={$EditSource} :)(:ifend:)
!!!$[Edit Message]: %color=#009%{$EditSection}
|| Subject:||(:input text name=$:subject{$EditSection} size=70:) ||
|| ||(:guibuttons:)||
|| Message:||(:input textarea id=text name=$:message{$EditSection} 
 cols=80 rows=12 class=inputtext:) ||
(:if enabled EnableAccessCode:)
|| ||Enter value {$AccessCode} (:input text access size=3 class=inputtext:)
(:input hidden accesscode {$AccessCode}:)  <- $[Have you entered the code number?]||
(:if enabled EnablePostCaptchaRequired:)
|| ||Enter value {$Captcha} (:input captcha class=inputtext:) <-
 $[Have you entered the code number?]||
(:if:)
|| Author:||(:input text author value='{$Author}' size=30 class=inputtext:)
 (:input submit post '$[Save]':) (:input submit preview '$[Preview]':) 
 (:input submit cancel '$[Cancel]':) ||
(:foxend editform:)
(:if foxpreview:)
%green center%[+&ndash; $[Changes have not been saved] &ndash;+]

This will add edit links to new posts, but not to existing posts.
Existing posts need a manual addition of editlink="{[foxedit nnn]}",
nnn shall be the post (message) number.

Release Notes

  • 2017-06-16: replaced Markup_e() calls with Markup() calls, for PHP 7.2 compatibility.
  • 2014-02-21: fixed markup definition to be PHP 5.5 compatible.
  • 2012: fixed bug editing anchored sections. Needs update to latest fox.php as well.
  • 2011-08-10: Added dynamic section edit link capability. Changed defaults for edit form locations to form templates on page Site.FoxEditForms (needs to be created!)
  • 2008-07-03: Added preview capability, when used with latest fox.php and foxedit forms with Preview button.
  • 2008-05-06: Added ability to open an empty page for editing. Foxedit can now open new pages in an edit form.
  • 2008-04-27: disabled modification of page variables by Qualify function.
  • 2008-04-21: modified the form check (it broke FoxContacts editing).
  • 2008-04-19: Added check for loading right type of edit form according to PTV name or #section supplied in foxedit link. Added tooltip option.
  • 2008-04-18: Tydied up edit form handling. Fixed bug with handling of html special characters.
  • 2008-03-29: Reworked code to make it more stable and suitable for general page edits. Change default edit form settings. Added hard-coded default forms in case default edit forms are not set.
  • 2008-01-17: Added error message if edit form does not exist.
  • 2007-11-19: Initial release.

If the recipe has multiple releases, then release notes can be placed here. Note that it's often easier for people to work with "release dates" instead of "version numbers".


<< Preview Button | Index | Delete Links >>