Fox Edit

Summary: add edit links for section and PTV edits
Version: 2008-07-03
Prerequisites: pmwiki 2.2.0 beta, Fox
Status: new
Maintainer: HansB?
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]}

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

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:

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]:           %green%[-–
 $[Changes have not been saved] –-]
>>frame<<
(:foxdisplay:)
>><<
(:if:)

(:fox editform foxaction=replace put=overwrite  target={$EditTarget}{$EditSection}
 redirect={$EditTarget}{$EditSection}:)
(:foxtemplate "{$$text}":)(: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 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.

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 {$$deletelink} {$$editlink}
  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

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".