Recent Changes - Search:

Cookbook

PmWiki

pmwiki.org

EditDataPages

Summary: Bring the wiki's View and Edit commands to ZAP data pages
Version: 1.0
Prerequisites: PmWiki 2.2, ZAP (Acme)
Status: in active use
Maintainer: Ben Stallings
Categories: Forms, Data

Questions answered by this recipe

This section is optional; use it to indicate the types of questions (if any) this recipe is intended to answer.

How can I use ZAP with the wiki's edit function, so that data pages can be viewed like regular wiki pages and edited by clicking the regular Edit link (but using a ZAP form), rather than having to add a separate link or button to edit the page?

Description

  1. Put the following in your config.php:
    ## If the group has an EditForm, use that instead of the site's
     $group = FmtPageName('$Group',$pagename);
     if ((PageExists("$group.EditForm")
      and (!in_array(FmtPageName('$Name',$pagename), 
       array($group,'GroupHeader','GroupFooter','EditForm')))))
      $PageEditForm = "$group.EditForm";
    ## Don't include EditForm pages in lists of "normal" pages
     $SearchPatterns['normal'][] = '!\.EditForm!';
    
  2. Edit the GroupHeader or GroupFooter of the page group where your data pages are stored. Make a template there that will display the data in a page when the page is viewed, like this:
    ||border=0
    || Field 1:||{*$:field1} ||
    || Field 2:||{*$:field2} ||
    
    (The asterisks indicate the data values are to be taken from the page being displayed, rather than from the GroupHeader or Footer page.)
  3. Edit the EditForm page of the group and make a ZAP form, like this:
    (:zapform:)
    (:zapdata:)
    ||border=0
    || Field 1:||(:input text field1 "{$field1}":) ||
    || Field 2:||(:input text field2 "{$field2}":) ||
    || (:input submit value="Save Changes":) ||||
    (:input hidden savedata "field1,field2":)
    (:zapend:)
    
  4. Set group and page permissions. You will want to restrict editing of the EditForm page in particular! However, for pages that users will be editing you will need to give them both edit and zap permission -- the first to view the editing form, the second to submit it. You may need to explicitly give the users zap permission to the group even if you have not specified a site-wide zap password.

Notes

Because DataQuery uses the ZAP format, this technique can be used to edit database records. It forms the basis for the upcoming DataPlates recipe.

Use of a custom EditForm will prevent your users from deleting data pages in the traditional PmWiki way (by typing "delete"), so you will want to look into either ZAP's delete function or the DeleteAction recipe.

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

Comments

This is a very creative use of ZAP, something I never dreamed of--and I am not sure I still understand the full implications of it. But I should point out there are easier ways to set up ZAP forms that update data, such as simply putting them in a group header or footer. I'm excited about Ben's upcoming DataQuery recipe, and glad ZAP can be a part of it. But wanted to point out here that in most situations, there may be easier ways to accomplish the goal of this recipe. See the ZAP demo site at www.zapsite.org for more information. Good luck Ben! Caveman

Thanks, Caveman! The disadvantage of putting a form in the group header or footer is that then you need conditional statements -- often several of them -- to control when the template is shown, when the form, and when the link to switch from one to the other. The wiki already does all this for you: it automatically hides the header and footer when you're editing, it shows the form only when you're editing, it provides a link to edit the page, and it controls who can edit and who can't. All those conditionals -- required in your method -- are redundant if you put the information in the right places to begin with. The only missing piece is providing for a custom edit form, which is what this recipe does. Once you have it in place, I feel this method is actually simpler, because you don't need any conditional statements.

That being said, the disadvantage of using a custom edit form is that there's no way to edit the page normally! Perhaps I'll find a way to shut it off -- perhaps for a given user or group, or just for those with admin privs.

Thanks for the feedback! Ben Stallings February 03, 2007, at 09:00 AM

Haven't followed this discussion as it's not on my notify list, but now see your reasons for this recipe a bit more clearly. The solution for your question, may be to set up a new action--like action=data or action=dataedit. When triggered this would load a page that simply retrieved a ZAP form. Just an idea... Better still, it would be neat if you could scan the page for PTV's, dynamically generate your data edit form, prepopulate the fields, and bingo, a sitewide action. That would be very cool--and not to hard to do...

See Also

ZAP

Contributors

Ben Stallings

Edit - History - Print - Recent Changes - Search
Page last modified on June 26, 2007, at 04:25 PM