Fox Contacts

Summary: Create personal or business Contacts pages and lists with Fox Version: 2017-05-20 Prerequisites: PmWiki 2.2.56, Fox, FoxEdit, FoxDelete (optional) Status: stable Download: see Cookbook:FoxContacts

Description

An application using Fox to create and maintain pages in a Contacts group, which store contact information in form of PTVs (Page Text Variables).

Copy the page files from Attach:foxcontacts.zip into your wiki.d/ folder, and the Contacts.php file into your local/folder. Install Fox, FoxEdit and FoxDelete if you have not done already.

This will create a group named Contacts, with the following pages:

  • Contacts.Contacts - index page
  • Contacts.NewContact - form to add a new contact and edit existing contacts
  • Contacts.ContactTemplates - all fox templates for the forms
  • Contacts.GroupHeader - with directive for display of Contact PTV data

New contacts are created as new pages in the group, and listed on the index page.

Optional add a pagelist for the sidebar or rightbar to list all contacts:

*[[NewContact]]
!!!!Contacts:
(:pagelist group={*$Group} list=normal fmt=#title name=-*Template,-*Contact* :)

With custom display templates one could display for instance telephone numbers or email address next to the name. Example, using simple table markup:

(:pagelist group={$Group} list=normal fmt=#customlist name=-*Contact*:)

(:if false:)
[[#customlist]]
(:template first:)
||
||!Name ||!Phone ||!Email ||
(:template each:)
||[[{=$FullName}|+]] ||{{=$FullName}$:telephone} ||{{=$FullName}$:email} || 
[[#customlistend]]
(:ifend:)

Or other index pages could be added with special listings of selected contact details.

Live example: Contacts (editing and deleting not allowed in this example, and edit and delete links not displayed, they display and function for users logged in)

Notes

The NewContact form acts in two ways:

  1. it is used to add a new contact page, using a template.
  2. it is used to edit an existing contact, called by a FoxEdit link, by updating the PTVs of the page.

These two very different functions are combined in one form, and that needs some specific syntax constructions.

The fox template '#new' on the ContactTemplates page is used to add PTVs. If we wanted only PTVs added, we would not need a template, but just need to set the names of PTVs in a list with commas separating each name to a parameter ptvfields=. Those PTVs could be hidden (default) or in some other visible form, using parameter ptvfmt=text or deflist, or section.

The GroupHeader contains a (:include ContactTemplates#display basepage={*$FullName} :) directive. It provides a way to display the 'data' of the PTVs in the page. Basically it displays (includes) section #display from page ContactTemplates, and uses the values of the PTVs on the specific Contacts page. This has the advantage that we can edit and change the display on all contact pages by editing a single template section, the data and the display of it are separated.

The ContactTemplates#display template section contains a foxedit and foxdelpage link markup, which are only shown to an authorised admin person. Also on the index page each list item has a 'X' link next to it, for convenient page deletion, shown only to an admin person.

Finally in this very brief explanation we can see that each Contact page has also a Comment form at the bottom, for easy adding multiple comments. This is just a basic Fox comment form, and an add-on to the functionality, which could be stripped.

Release Notes

  • 2017-05-20: Updated NewContacts form and ContactTemplates to work with latest fox.php (version 2017-05-20 or younger). Removed (:title ... :) from being added to new contact page, and allow updating the name fields.
  • 2015-01-10: Added page exists conditional to GroupHeader to suppress template display when page does not exists. Fixed conditional for posting new comment notes. Simplified note template.
  • 2015-01-08: Simplified display template, by using basepage= parameter in the directive in the GroupHeader. Added page delete links to index list for admins. This version needs updated FoxDelete script (version 2014-01-08 or later).
  • 2014-08-22: added ptvclear=1 to (:fox....:) markup in NewContact form to allow clearing of PTV with empty input.
  • 2010-03-17: Fixed bug which did prevent editing names with spaces
  • 2010-03-10: fixed a number of bugs, improved templates.
  • 2008-03-29: simplified to use single form for adding and editing pages. For use with latest versions of Fox and FoxEdit
  • 2007-11-23: 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".

Comments

Neat. Any thoughts on how to get a vcard?
    Also, suppose I added a "birthday" field.  Any idea how that could be integrated with
    one of the calendars, say PmCalendar??  (I'd hesitate to simply add a name to a date
    page, as we might have to correct birthdates later.  I also wouldn't want to make a
    calendar loop over every contact page for every date.) -- rlt
Very flexible and useful. However, the delete function only deletes the content lines but not the contact. Therefore, pagelist still thinks the contact exists and will list deleted contacts in the contact list. To actually delete a contact, the content should, in this case, be replaced with 'delete'. How do I do that? -- jhj
Set in alocal config for your contacts group (for instance in local/Contacts.php);
$DeleteKeyPattern = "^\\s*$";
Now a page will be deleted if it is empty. So the fox deleterange link or button will erase the page as well. HansB?
PKHG speaking: Hans (reply by e-mail?), if you specify the layout of a birthday, I could adjust the GcalPmWiki to allow

Birthday-Groups (as you use it here for Contacts) to scan all "BirthdayGroup".* files for birthdays (only the first one? or several?) or a Birthday-only-Kalendar

Hans: The edit screen (form=FoxEditContact)on your demo website is missing the captcha. Attempts to edit and existing contact and then save trigger the messgae "ERROR: Missing or wrong Captcha Code!" Pico? November 20, 2007, at 03:50 PM

Thanks for catching that! I fixed it now on my site. I left out captcha or access code from the recipe here, as I think that will in any case have a Contacts group under lock, either with edit or with read access restricted. HansB? November 20, 2007, at 04:17 PM

I have just tried to install FoxContacts and I am getting the following error when I select the edit a contact link:

PmWiki can't process your request

Error: wrong PTV name in foxedit link or edit form not suitable for PTV editing!

We are sorry for any inconvenience.

I also found that I needed to install foxdelete.php to make the delete links work which was not documented (is that correct). I have searched for this error message but I can't figure out what I have done wrong, I have not edited the pages or anything they are just how I downloaded them and I have saved all the files to default directories. Any help much appreciated - Neal : April 21, 2008

Thank you for pointing this out! There seems to be a bug in the latest FoxEdit regards the form check. Till this is sorted please set in config.php $EnableFoxEditFormCheck = 0; - HansB? April 21, 2008, at 05:02 AM

This bug is now fixed in FoxEdit - HansB? April 21, 2008, at 05:17 AM

Thank you - Neal

Hi Hans - nice recipe. If I want to add a field do I add it to ContactTemplates and any existing contacts? Thanks Matt May 4, 2010

Yes, but you also need the extra input field in the form in page NewContact. - HansB? May 05, 2010, at 11:59 AM

Hi Hans, Fantastic recipe and I'm looking forward to doing more with Fox. One question at this point, is there an easy way to establish multiple "Contact" groups within a single Wiki? I'm using pmwiki as an Intranet, and would like for individual groups in my organization to have their own contact directory.

The files in the zip are for setting up a Contacts group. But you can rename them for setting up the contact form etc. for different groups. Basically all is self-contained in one group, so several differently named contacts groups will work. One could of course put the ContactsTemplates page into the Site group to have just one page for the templates. Then the NewContacts form need adjusting to use its template from there, and the templates themselves need some adjusting to use Site.ContactsTemplates rather than just ContactsTemplates. - HansB? May 05, 2010, at 05:24 PM

Hi Hans, really am starting to love Fox, incredibly useful tool for use with PMwiki. I'm a noobie when it comes to working on this stuff, but persistant, and have been able to puzzle my way through things, with the help of Google. Now, my question about Fox Contacts, you mentioned that with custom display templates you could add email or phone to the pagelist. Well, I've read everything that I could on templates and PTV and hunted the internet, but have come up dry. I can't believe that someone hasn't wanted to do the same thing with FoxContacts, but I can't seem to find anything. Do you have an example of how I could add a field from a FoxContact to a PageList? If I can see one example, I'm sure I'll be able to build my own template sucessfully (as opposed to now, where I think I'm on version 10, with no success). Thanks!!!

Sure! I added an example above for a custom pagelist template displaying title (Contact full name), telephone and email. The last two are PTVs, note the curly brackets inside curly brackets. {=$FullName} always refers to each pagelist item (contact page) processed by the pagelist function. A PTV from another page is displayed like {PageName$:ptvname}, so in the pagelist template PageName gets replaced by {=$FullName}, which gives {{=$FullName}$:ptvname} for the PTV inside the template. Add link markup and styling etc. as needed - HansB? June 04, 2010, at 02:09 AM

See Also

Contributors