[pmwiki-users] Using forms to introduce and edit constrained PmWiki markup

Ben Wilson dausha at gmail.com
Sat May 19 08:22:48 CDT 2007


On 5/19/07, Harry Forsdick <harry at forsdick.com> wrote:
[...]
> This all works quite well, but I am finding that people in the organization still feel uncomfortable with using free form markup to specify and edit their calendar entries.  So, I would like to see if I can use a form to create and edit a calendar entry.
>
> This brings up two related considerations relating to the production of PmWiki markup as the result of the output of a form and (in a related but different issue) how to create a new directive that expands into PmWiki markup (instead of HTML).  I really like the power of PmWiki markup, but frequently would like to create these "macros".
>
> Since each entry can be represented on a separate line in the buffer, and I know how to parse a single line to get the various tokens of the directive, I know how to take an existing PmWiki page buffer of my restricted markup, and represent it in a form.
>
> The part that I do not know how to do is how to get at the contents of the PmWiki markup in a page and the related issue of how to replace the contents of a PmWiki marked up page with the output of a form.  I assume I am going to have to have a separate  edit link in the output representation of the calendar items.
>
> Can anyone help me revealing how I can do this?

Here's an approach:

1. Build a markup for your form: (:kalendra-form:):

Markup("kalendra-form","directives","/\(:kalendra-form:\)/e",
           "RenderKalendraForm();");

2. Create the "RenderkalendraForm" with the appropriate markup. The
example below will return the PmWiki markup that will then be
processed. I'll assume you know how to build a form in PmWiki:

function RenderKalendraForm() {
    return<<<OUTPUT
(:div id=kalendra:)
put your form here
(:input type=hidden name=action value=kalendraform:)
(:divend:)
OUTPUT;

# Or, if reading from another page:
    global $KalendraFormPageName
    $page = ReadPage($pagename);
    return $page['text'];

}

3. Build your return function. You'll have to decide what the action
is and build that into your form. I'm doing this of the top of my
head, so you'll need to verify the functions I'm calling.

$HandleActions['kalendraform'] = 'HandleKalendraForm';

function HandleKalendraForm($pagename, $auth='edit') {
    # Get your form input via $_REQUEST
    # Convert input into wiki markup
    # Retrieve target page and clone ($new = $page =
ReadPage($pagename, $auth);)
    # Do your text work on $new
    # PostPage($pagename, $page, $new);
}

That should give you a start. Perhaps this discussion could be
continued on pmwiki-dev?

-- 
Ben Wilson
"Words are the only thing which will last forever" Churchill



More information about the pmwiki-users mailing list