[pmwiki-users] How to add a read password field to the edit form

Peter & Melodye Bowers pbowers at pobox.com
Mon Aug 11 08:44:25 CDT 2008

> This would be my first recipe, but I need way more code ... or someone
> to do it for me .-)

I'm afraid I can't code it for you, but you'll be looking at something like
this (I haven't even compiled this, so be aware of what level it is)...

$EditFunctions[] = 'AllowPublicPage';
# AllowPublicPage()
function AllowPublicPage($pagename, &$page, &$new) {
  $rpw = $page['readpasswd']);
  if (@$_REQUEST['allowpublic']) {
    if (!strstr($rpw, 'id:*')
      $rpw .= ($rpw?" ":"") . 'id:*';
  } else {
    if (strstr($rpw, 'id:*')
      $rpw = str_replace('id:*', '', $rpw);
  $page['readpasswd'] = $rpw;

This assumes you've named your checkbox field "allowpublic".

There's definitely more efficient ways to do it (I think there's some way to
combine my 2 nested if's into a single if/else).

I'm not confident at all that I've correctly handled the existing read
passwd, either appending or getting rid of the 'id:*'.

I have no idea if the order of the functions in $EditFunctions is
significant - I would guess that it is...

But this should get you further down the line...


More information about the pmwiki-users mailing list