Fox-Talk

Summary: Talk page of Fox

Back to Fox

Please put a new question at the top, with its own header


fox stopped working

for pmwiki 2.3.5 fox stopped working. As soon fox.php is copied to cookbook/fox directory I get an Error 500.

Strange thing: I before updating from pmwiki 2.2.107 everything worked fine. (OK, reverting to old version does not help neither, maybe some incompatibility with newer PHP version (8.0.19)? )

I have no idea where to look or what to fix. Any ideas? Klonk 2022-05-24

I am unsure if HansB is monitoring this page, it may be better to contact him directly. --Petko

HansB: I see it is broken with php 8. I try to get this fixed, but at first glance seems hard for me to adapt script for php 8+. Lots of undefine dvariable error messsages. Most likely also other recipes I authored will be affected. HansB: New version to fix bugs occuring with using PHP 8.1 released. - @2022-11-01


Minor problem in (:foxtemplate:) markup

Currently line 137 reads as follows:

 Markup('foxtemplate','<input','/\\(:fox(display|preview|)template\\s+"(.*?)\\s*":\\)/', "FoxTemplateMarkup");

But this means that no whitespace is permitted between the closing double-quote and the closing :), i.e. this

 (:foxtemplate "My Cool Form" :)

would not be parsed properly. This is not how most directives work!

Here is the fix. Replace line 137 with this:

 Markup('foxtemplate','<input','/\\(:fox(display|preview|)template\\s+"(.*?)\\s*"\\s*:\\)/', "FoxTemplateMarkup");

Said Achmiz November 11, 2017, at 02:16 PM


PHP Warning in fox.php

SteP 20151029 - I upgraded fox.php to version 2015-09-30 and I'm starting to see PHP warnings:

PHP Warning:  Illegal string offset 'taridx' in /mnt/www/pmwiki-2.2.78/cookbook/fox/fox.php on line 1205
PHP Warning:  Illegal string offset 'taridx' in /mnt/www/pmwiki-2.2.78/cookbook/fox/step-fox.php on line 1205
PHP Warning:  Cannot modify header information - headers already sent in /mnt/pmwiki-2.2.78/pmwiki.php on line 1240

It happens on a foxmail action with a template that has always worked before, although with a much older pmwiki+fox+foxnotify installed set:

[[#default]]$[Date]: $PostTime 
$[Subject:] {$$subject}

{$$text}
[[#defaultend]]

With $FoxDebug=5 I can see that the template is processed correctly:

UPDATEPAGES> 
TARGET=FoxNotifyLists.Nobody PERMISSION>FoxNotifyLists.Nobody mail TEMPLATE>FoxNotifyLists.Template-contact ACTION>mail INDEX=0

Eventually becoming:

ENGINE> 
TEMPLATE-VR>
VREP=
$[Date]: $PostTime 
$[Subject:] {$$subject}

{$$text}
VALUE(subject)=test0
VALUE(text)=test20
VNEW=
$[Date]: $PostTime 
$[Subject:] test0

test20

The offending source code line is:

$maxcnt = $FoxMaxIterations + $d['targ']['taridx'];

And print_r($d) shows 'targ =>', that is, targ is empty. I don't know why fox gets there with an empty targ, but looking at the purpose of that line, I guess it's OK to temporarily patch it with some test on an empty targ, maybe adding 1 when targ is empty. What do you think?

HansB: thank you, yes, the $targ variable was not passed on to the FoxNotifyUpdate() function, and then not passed back to the FoxTemplateEngine() function. I corrected this with the latest updates to fox.php and foxnotify.php. Please update both.

SteP: Thanks for the fix, I can confirm it works here. I also appreciate the debugging statements in your code; they have helped me many, many times.

HansB: me too! :) It has grown into quite a complex script, so making debugging a bit easier is quite important. I added the show() function I often use, to insert into the code when and where needed, to show variable values. Simple use like show($array,'label'); or show($var,'label');. Arrays get labelled and formatted echoed output.

SteP Yes, I had noticed show() while I was going over the code changes you made. I think I will adopt show() for my own scripts!

Validating for negative condition

Since foxcheck regex uses preg_match instead of regex, how do we check that a field doesn't have something in it? I'm having no luck trying to pass parameters to preg_match.

I don't want people entering links, so I want an error condition if http or www. is in any field. UrlApprove doesn't work for me, as I have numerous links in my sidebars and would generally be a pain. This is for a user comment area.

Never mind. It took most of the day, but after going through numerous permutations of preg_match parameters I found the ones it likes for a negative condition:

(:foxcheck regex='(?=^((?!StringYouDoNotWant).)+$)' ptv_field msg='Generic error message.':)

Also: List=check in foxmessage isn't working for me. I have to use one message per field regardless of the error. As I check for only two conditions, no data or URL, both aren't going to happen in one field at the same time.

- Jerod Poore 19 May 2015

HansB: the syntax is: (:foxmessage <formname> list=check:) (small letters for list=), and it needs the form name.


Looking for a very compact way of displaying and updating a PTV

Hi again. I want to have a "one click" method to update a PTV on a different page then the one displayed and return back to the displayed page.

I have a "Progress" PTV that can contain the values 0-1 in .1 increments and a method using if/then/else statements to display a simple, compact bar graph with pipe and . characters. Currently, I have dummy links to the target page for each of the characters so that by clicking on a character I could update the target page PTV with the newly selected value. Could each of those characters be a foxform to do the update? I don't want to make the users go to another page to pick the new value and save it. I also don't have room for a button for each of the fox forms if I went that route. If pmwiki had something like a "PTV assign value" action, my method would work. Maybe I'm trying to get pmwiki/fox to do something that they were never designed to do.

- DannyB 29-May-14, at 17:24

Fox does not allow form posting via links for security reasons. I think the easiest would be to use css to style the Fox submit buttons to appear as links. Here is an example, where I wrapped the forms in a div with class "inline", and defined that class in pub/css/ in a page specific file:

wiki test page:

(:foxmessage:)
>>inline<<
Enter data: 
(:fox frm1 ptvfields=data1 ptvtarget=Test.PTVUpdate:)
(:input hidden data1 value=1:)(:input submit post 1:)
(:foxend frm1:)
(:fox frm2 ptvfields=data1 ptvtarget=Test.PTVUpdate:)
(:input hidden data1 value=2:)(:input submit post 2:)
(:foxend frm2:)
(:fox frm3 ptvfields=data1 ptvtarget=Test.PTVUpdate:)
(:input hidden data1 value=3:)(:input submit post 3:)
(:foxend frm3:)
>><<
data display = {Test.PTVUpdate$:data1}

css:

.inline form, .inline p { display:inline!important; }

.inline .inputbutton {
	border:0; background:none; 
	cursor:pointer;
	color: #226BAF;
	font-size:.9em; 
	text-decoration:underline;
}

HansB May 29, 2014, at 04:08 AM

Thank you for that solution. I figured css would come into play. I wanted the digits right next to each other: 123 rather than 1 2 3. So I went to negative right margins in the css on both the form and inputbutton to finally get them closer. I love how it works.

DannyB 30-May-14, at 14:56


Problems with foxfilters

Hello. I use fox on my wiki with great success ! But I have 3 problems with foxfilters. I don't understand the origin of them.

I. When I use a foxfilter in a form with an input validation (:foxcheck ...), the foxfilter works, but not the input validation.

Example of filter: (in the local.php config file)

 $FoxFilterFunctions['marqueurs'] = 'FoxMarqueursFilter';

  function FoxMarqueursFilter($pagename, $fields) {
    $fields = preg_replace('/\[\[\#/', '&#x2665;', $fields);
    return $fields;
  }

And my form:

(:foxmessage:)
(:fox commentaires foxfilter=marqueurs ptvtarget={*$FullName}:)
(:input hidden $:compteur "{(add {{*$FullName}$:compteur} 1)}":)

2 + 3 = (:input text captchareponse:)
(:foxcheck captchareponse match='5' msg='Réponse incorrecte':)

(:input submit post $[Save]:)

(:foxend commentaires:)

The captcha doesn't work with foxfilter, but works without the foxfilter. The foxfilter works with or without the input validation.

II. When I use foxfilter with two or more input markup, the form doesn't work and i have an error message (from system)

Warning: Invalid argument supplied for foreach() in /dns/in/(...)/cookbook/fox/fox.php on line 527

Wich is repeated 12 times when i submit the following form.

(:foxmessage:)
(:fox test foxfilter=marqueurs:)
(:foxptv {*$FullName} ptvfields=compteur:)
(:foxadd target={*$FullName} template="{$$captchareponse}":)
(:input hidden $:compteur "{(add {{*$FullName}$:compteur} 1)}":)

2 + 3 = (:input text captchareponse:)
(:foxcheck captchareponse match='5' msg='Réponse incorrecte':)

(:input submit post "Je poste un commentaire":)

It doesn't work even if i use a markup (:input hidden foxfilter marqueurs:)

III. In my case, the function EnablePostDirectives doesn't work, even if I put

EnablePostDirectives = false; in my local.php config file.

Thanks for your responses.

Benji November 26, 2013, at 09:59 AM

I can see that your foxfilter function messes up arrays which are part of $fields. Can you rewrite the foxfilter function so your replacements will be done for specific fields? Set in fox.php $FoxDebug = 5; Then you see how the input variables are manipulated. For instance you should see something like

    [chk_name] => Array
        (
            [1] => captchareponse
        )

and not just

     [chk_name] => Array

(this is a part from the foxcheck input). In the latter your foxfilter function destroyed the nested array. Hope this helps! HansB November 26, 2013, at 11:43 AM


Disable per page? Is there a markup that I can put say at the top of the page (in the same way you would (:noleft:)) that would disable all fox forms for that page? I have a template page that I occasionally copy to the regular page (part of a todo list) and have found that I accidentally use the fox form on the template instead of on the regular page. I know this can be done from the SiteAdmin.FoxConfig page, but something simpler is desired as well. Thanks ~vericgar 2013-02-02 15:12 PDT

Do you want to disable form submission (any input will not be processed)? fox has no build-in conditional markup to that. Or do you want to hide the fox forms? For this you could perhaps use conditional markup to check that the form is on the right page, and if not it would not show? - HansB February 04, 2013, at 01:09 PM


Can Fox update PTVs with varying values, based on select form? I have the need to update PTVs with values that depend on what is selected in a input select form. Let's assume there is a fox form that includes an input select form called "Model" with Options "A" and "B". On the template page, there are 2 PTVs: (:Color::) and (:Height::). I would like to be able to create a new page from this template, but if "A" was selected, then on the target page set (:Color:Blue:) and (:Height:5feet:), if "B" then (:Color:Red:) and (:Height:2feet:). - MichaelD 12/01/2012, at 2:57 AM

HansB: Sorry for responding so late! Fox has not got some kind of conditional input processing. The best I can think of, for just one set of input options, is to give those options values, which are different template locations, and set your template= in the form to the select input name, or better to name your select input 'template'. And then add your PTVs with relevant values to the different templates. Here is a simple example, with three different templates, all on one page:

(:foxmessages:)
(:fox frm :)
(:input select template #choiceA A:)
(:input select template #choiceB B:)
(:input select template #choiceC C:)
(:input submit post:)
(:foxend frm:)

(:if false:)
3 templates, according to choice:
[[#choiceA]]
A template...
[[#choiceB]]
B template...
[[#choiceC]]
C template ...
[[#choiceCend]]
(:if:)

Is there a way to add a "fox edit page using a fox form and template" action?

I want to have a page of data displayed and follow a link via the action menu line ("View Edit History...") which would edit the page via a fox form. So in essence add a Form link that went something like: http://.../Projects/1200123?action=foxedit This would call a fox form named something like Forms/ProjectsUpdate and use FoxTemplates/ProjectsUpdate for the template where "Projects" is the group name and "Update" is for updating an existing page. In essence a "one click" to edit a page via a fox form. - DannyB 26-Oct-12, at 18:00

Have you looked at FoxEdit? FoxEdit adds a markup {[foxedit]} which creates an edit link to open a page section for editing with a special Fox edit form. It seems to be exactly what you are looking for. - HansB October 26, 2012, at 03:19 AM

Thanks for directing me to foxedit. That is what I need, but when I read the documentation previously I did not think there was a way to edit a whole page. Now I just need to have it fill in the form defaults with the values it finds on the page I'm editing. Here is the markup I placed, via a "fox include", onto the page I wanted to edit. {[foxedit form=Forms.ProjectNew source={*$FullName}]} It takes me to the correct page, but do I need to have some "default" specification on the form for each input field? It would be nice to have the source=... grab the values from that page and fill-in the default values on the form when it is displayed. - DannyB 31-Oct-12, at 16:30

Please take a look at FoxContacts. It operates in one wiki group. It uses one form (on page NewContact) for adding a new page and for editing a page. All data is added a s PTVs, and edited as PTVs. It uses principally two templates (on page ContactTemplates): one for displaying PTV data, and one for creating a new page with PTVs. The display is handled via an include markup in the GroupHeader page, where the display template is included and filled with the values of the PTVs of the page. The beauty of this approach is a complete separation of data as PTVs and display of the data. You can change the display of all Contacts pages by just modifying the display template. - Anyway, this may not be what you want, but the NewContact form should give you a good idea how to populate a form with PTV data. You see in it the markup (:input defaults source={$EditSource} :), which serves to collect the PTV data, when the form is invoked via a {[foxedit form=NewContact]} link, which is part of the display template. The form will save changed/updated PTV data, because of ptvupdate=1 in the (:fox contactform ...:) markup. Whereas put=top and template=ContactTemplates#new serves when the form is used to create a new Contacts page. An input text field like (:input text name=$:address1 size=60:) refers to the PTV address1 of the target page (either to be created or to be edited). - In this explanation of the workings of FoxContacts I ignored the additional comment form you will see, because it is not relevant to your question, nor essential to FoxContacts. - Lastly, you do not need to use the same form for adding and for editing, you could use two. And you do not need to have that separation of data and display, achieved by the (:include ContactTemplates#display ... :) markup in the GroupHeader and the display template. Just make sure that whatever you wish to edit is PTV data, then create corresponding input fields to grab it on form load. - HansB October 31, 2012, at 05:09 AM

Thanks again for pointing me in the right direction. I'll take a look at how it's done. Our wiki is already separated into groups of related pages. I do like to keep data and display information separate. It does look like there may be an issue with only dealing with PTVs. Some of my groups have pages with multi-line notes in them marked out like [[#story]] ... [[#storyend]] in the template. I'll need to see how to deal with that. I think this forces me to go with one page for creating and one for updating with a [[foxedit]] link to edit the multi-line story sections. - DannyB 05-Nov-12, at 8:34

you should be able to load and edit such a section in a textarea input field as a PTV (named story). - HansB November 05, 2012, at 02:27 AM


Problems with the {=$:PTV} feature

The revision that you made seems to work sometimes and not others. I cannot figure out what the issue is. All I found was that sometimes the {=$:PTVs} get processed and other times they don't.
Any ideas? Compress this description as you wish. - DannyB 25-Oct-12, at 5:20

Thanks for pointing this out! This was a bug. All PV and PTV template variables got only evaluated if one was present for the current page. Now fixed in new fox.php update. - HansB October 25, 2012, at 08:53 AM

Thanks for the fix. - DannyB 26-Oct-12, at 10:42


Get the value of a PTV from another page

Is there a way to get the value of a PTV from another page and assign that value (not the reference) to a new PTV being created via a form. Is this possible with markup in the form or fox template? How do I get a PTV reference to "expand" to just the value of the PTV?

Example of the problem

$$Proj_Ethno_Code = KBQ via form submission of field Proj_Ethno_Code.
If the PTV 'Language' on page 'Languages/KBQ' has the value 'Kamano-Kafe', this markup in the template {Languages/{$$Proj_Ethno_Code}$:Language}
produces this value: {Languages/KBQ$:Language}
Is there a way to get it to expand to the next level to assign the value Kamano-Kafe to the PTV on the new page? This is the markup in the template. :Proj_Language: {Languages/{$$Proj_Ethno_Code}$:Language} Thanks for your help with this. - DannyB added example on 15-Oct-12, at 11:56 (I compressed your query, HansB)

With the latest fox.php you can now use in your template:

:Proj_Language: {Languages.{$$Proj_Ethno_Code}=$:Language}

Note the new {=$:ptvname} and {PageName=$:ptvname} syntax. Such PTV (and PV) replacement variables will get evaluated on form submission. See also documentaion for Fox templates- HansB October 15, 2012, at 04:44 PM

Thanks for implementing the new feature so quickly. I downloaded the new fox.php version ("2012-10-15"), copied it to the cookbook/fox folder but it produced the following results: {Languages/KBQ=$:Language} It's like it does not go the next level. Any ideas? Our server is running on a local network with apache 2.2.14 and php 5.2.9 . - DannyB 17-Oct-12, at 17:49

HansB: Works fine here, with various tests of using replacement variables. Perhaps try another download of fox.php and install that.
Please try this testing procedure:

  1. Ideally do this with a stripped down simplified form and template first, before testing your full form.
  2. If your Fox form uses a redirect than disable that in the markup for this tests.
  3. Open fox.php in a text editor.
  4. Check you got the latest version.
  5. Change near the top $FoxDebug = 0; to $FoxDebug = 5; (the highest debug level).
  6. Now do a test form submission. You will get lots of debug info echoed to the screen, before you see your normal page further down.
  7. The debug info will reveal how the variables are replaced. You can send me a copy of the debug info (copy from the screen) for analysis (design @ softflow.co.uk).

Here is a simple test form I added to page WikiSandbox. It operates on one page (takes PV and PTV values and posts to same page). Test it, then modify it to draw PTVs from a different page:

(:title Testing Fox Replacement Variables:)
data1: 1111
data2: 2222
(:foxmessages:)
(:fox testform template=#tmpl:)
(:input text txt1 'WikiSandbox':)
(:input submit post:)
(:foxend testformend:)
(:if false:)
[[#tmpl]]
----
{$$(date:d.m.Y - H:i)}
new1: {{$$txt1}=$:data1}
new2: {{=$FullName}=$:data2}
title: {=$Title}
[[#tmplend]]
(:if:)

DannyB: I somehow ended up with a line of code missing from my previous download. Now it works! Thanks so much! That opens the door to a bunch of new options. For all your efforts to work with me in learning and modifying fox forms I gave you a donation.

One minor question. When I turned on the debug for my large template run, I could see the text scroll by in the Firefox window and then the debug text disappeared. The debug text stayed around for your short form. - DannyB 18-Oct-12, at 9:22

perhaps your form redirects to a different page after submission? You need to disable any redirect temporarily in the form (I usually just put an x in front, like xredirect=1). Thanks for the donation! Very much appreciated! HansB October 18, 2012, at 02:55 AM


Fill out input fields with default values from the target page

Is there a way to have fox forms fill in the default PTV values for input fields without specifying each of them? That would really minimize the amount of code needed to update PTVs via a form. DannyB 26-sept-12

HansB: I don't see any problem in populating form fields with PTV values, and having the form create new PTVs with these values (is that what you want?). Here is a simple example, working on one page:

(:foxmessages:)
(:fox frm ptvtarget={*$FullName} ptvfields=data1 ptvfmt=text:)
(:input text data1 value={$:data2}:)
(:input submit post:)
(:foxend frm:)
data2: abcdefg

field data1 gets filled with value of PTV data2. On submission PTV data1 is created. I added ptvfmt=text so you can see the new PTV (not hidden). You can expand the example to pull PTVs from other pages, and create PTVs on other target pages, at will. Hope this helps. HansB October 12, 2012, at 05:08 PM

'pmforms' has this description which is what we are after without having to specify the value="..." for each PTV on the form. This would make it nice for updating PTV values on a given page.

(:input default source={*$FullName} :)

instructs the form to auto-fill with the data values from the current page if they are available. This is a nice time-saving feature if you don't want to re-type all fields of a form to make a correction.

you can use (:input default .... :) markup like all (:input ...:) markup in Fox forms, it is not restricted to PmForms. See InputDefault for exact syntax, especially how to reference PTVs on another page ( name=$:ptvname ). HansB October 15, 2012, at 04:38 AM


Update two different PTVs with content from one form?

Is it possible to update two different PTVs (with different names), with the value from one input form? Ie: DannyB 15-Oct-12


TextBox, value entered: Hello

On submit: set ptv1 with "Hello" and also set ptv2 with "Hello"

Yes. Each PTV needs a form control with same name, but you can feed the value from one control to another using for instance a hidden field. Example:

(:foxmessages:)
(:fox frm ptvtarget={*$FullName}:)
(:input text ptv1:)
(:input hidden ptv2 {$$ptv1}:)
(:input submit post:)
(:foxend frm:)

ptv1: Hello

ptv2: Hello

Is it possible to submit a fox form without <Submit> button?

Also, is it possible to submit a fox form without having to use a <Submit> button, ie whenever the page loads?

There is no provision for form submission triggered by an 'onload' event, or other events, or through url parameters. This is a standard safety measure. - HansB


Fox form creates multiple pages when title/pagename contains spaces

Consider the form:

(:linebreaks:)
(:foxmessages:)
(:fox nuovoannuncio template=Site.BachecaTemplate redirect=1:)
(:input hidden foxfilter FoxSetPW:)
Titolo:
(:input text target size=20:)

Testo annuncio:
(:input textarea textbox rows=20 cols=60:)

Argomenti:
(:input checkbox name=argomento[] value='[[!Immobiliare]]':) Immobiliare
(:input checkbox name=argomento[] value='[[!Lavoro]]':) Lavoro
(:input checkbox name=argomento[] value='[[!Vacanze]]':) Vacanze
(:input checkbox name=argomento[] value='[[!Varie]]':) Varie
(:input checkbox name=argomento[] value='[[!Veicoli]]':) Veicoli

(:input submit post "Crea Annuncio":)
(:foxend nuovoannuncio:)
(:nolinebreaks:)

This form uses the following template:

(:title {$$target}:)

{$$textbox}

Argomenti:\\
{$$argomento}

When I use the form to create a page which contains spaces in the name, the form creates a page with the complete name, plus another page for each word in the title. For example, if I want to create a page named "This is a test page", it will create a page named "ThisIsATestPage", with the title "This is a test page". But it also creates a page named "This", a page named "Is", a page named "A", a page named "Test", and a page named "Page". The first page created (with the complete name) contains the text written in the form, but all the other pages are blank. Furthermore, I use FoxSetPW to set the edit password to the user who created the page. But in fact, the first page created (with the complete name) doesn't have the proper password set. Instead, it's using the site settings in config.php. All the other pages, with single-word names and no content, use the correct edit password as set by FoxSetPW.

On the other hand, if I want to create a page named "ThisIsATestPage", everything works as it should.

I'm stumped, I have no idea why my form is behaving this way. Any help would be greatly appreciated. -Ugo May 30, 2012, at 06:30 PM

HansB: Ugo, the FoxSetPW function in foxsetpwedit.php will create a list of target pages using spaces, commas or pipe characters (|) as separators in the argument supplied for "target". Edit the foxsetpwedit.php file by removing in line 9, a bit after preg_split, exactly \s (backslash and s), which is the space character in the regular expression of preg_split. If you think that commas may be part of your page titles, then remove the comma too in the square bracket of the regular expression. That should cure your problem.

HansB, I tried your hack to remove spaces and commas to create a list of target pages but I left the pipe in case I need multiple pages. It works fine for spaces, but multiple pages are still created when I use commas in the title. Line 9 is now like this:

$targets = preg_split("/[|]+/", $fields['target'], -1, PREG_SPLIT_NO_EMPTY);

Anything else I need to change?

Ahh, yes! fox.php will use a comma separated list supplied by the "target" parameter, to create multiple page targets. To avoid hacking fox.php you can use different markup in your form: Do not use template and target but something like this instead:

(:fox nuovoannuncio redirect=1:)
(:foxadd target={$$titolo} template=Site.BachecaTemplate:)
(:input hidden foxfilter FoxSetPW:)
Titolo:
(:input text titolo size=20:)
etc.

Here titolo is used instead of target. You need to change in your template target to titolo as well. What happens is that Fox will not expand comma separated entries from the foxadd markup, as it assumes only one target and one template within this markup. But one can have several foxadd markups in the form, to create multiple target pages.

HansB, thank you for your quick replies. I tried your suggestion, unfortunately now Fox doesn't create the page at all, it just fails silently and returns me to the page where the form is. This is the form that I'm using now:

(:linebreaks:)
(:foxmessages:)
(:fox nuovoannuncio redirect=1:)
(:foxadd target={$$titolo} template=Site.BachecaTemplate:)
(:input hidden foxfilter FoxSetPW:)
Titolo:
(:input text titolo size=20:)

Testo annuncio:
(:input textarea textbox rows=20 cols=60:)

Argomenti:
(:input checkbox name=argomento[] value='[[!Immobiliare]]':) Immobiliare
(:input checkbox name=argomento[] value='[[!Lavoro]]':) Lavoro
(:input checkbox name=argomento[] value='[[!Vacanze]]':) Vacanze
(:input checkbox name=argomento[] value='[[!Varie]]':) Varie
(:input checkbox name=argomento[] value='[[!Veicoli]]':) Veicoli

(:input submit post "Crea Annuncio":)
(:foxend nuovoannuncio:)
(:nolinebreaks:)

and this is the template file, Site.BachecaTemplate:

(:title {$$titolo}:)

{$$textbox}

Argomenti:\\
{$$argomento}

Fearing that I may be using some wrong options in config.php, here is the snippet of my config file relative to fox:

## Enable Fox
$EnableUndefinedTemplateVars = 0;
$FoxAuth = 'read';
if (CondAuth($pagename,'edit')) {
   $EnableFoxUrlInput = 'true';
   $FoxPagePermissions['*.*'] = 'all';
}
include_once("$FarmD/cookbook/fox/fox.php");
include_once("$FarmD/cookbook/fox/foxdelete.php");
include_once("$FarmD/cookbook/fox/foxsetpwedit.php");

I thought that maybe the conditional in config.php may be causing the problem, so I removed it so that $FoxPagePermissions['*.*'] = 'all'; would be always valid, but it didn't make any difference. By the way, I'm using the latest version of PmWiki and Fox.

okay, it is more complicated than I thought, since the foxadd markup avoids using target as name of the HTML form field, but the filter function expects it. Please revert back to the form and template you had first, using the target parameter, not the foxadd markup. Then edit foxsetpwedit.php and comment out lines 8,9 10 (the if ... else statement) and add a new line before these with

$targets = array($foxfields['target']);

basically simplifying the function so it takes just one argument for target as the new page target. This is what your form does, so the filter function is okay for that purpose, but not for processing lists of target pages.

I'm still having problems, I reverted the form and the template to the previous versions using the target parameters, and modified foxsetpwedit.php as you instructed. When I try to use the form now, I get this error message:

Warning: unlink(wiki.d/.): Is a directory in /var/web/sinet/food/pmwiki.php on line 1014 
PmWiki can't process your request
Cannot write page to (wiki.d/.)...changes not saved

On a hunch, I changed the line $targets = array($foxfields['target']); with $targets = array($fields['target']); and that got rid of the error, but now the form generates multiple pages again when I use a comma in the title.
Seems I'm good at finding complicated issues! Bear in mind that I'll never need to generate multiple pages on this site, so I could hack fox.php if you tell me where.

Sorry, I am going around in circles, and introducing more bugs! I don't like the idea of hacking fox.php. So let me try again: Revert your form and template to the version using (:foxadd target={$$titolo} ... and {$$titolo}, as this will avoid multiple target creations in Fox. Then change the last change in foxsetpwedit.php to $targets = array($fields['titolo']);. Try that. The filter function coud be simplified further, as we do not work on a list of target pages to set passwords, but let's leave the change as simple as possible for now. HansB June 01, 2012, at 02:29 AM

HansB: Finally, the form works perfectly! Single pages are created regardless of spaces and commas. I assume that from now on, I'll be using the field 'titolo' in any form that has to create pages from a user-input field and that uses the FoxSetPW function. I'm sorry for making you run around in circles, but in the meanwhile I've learned quite a few things on how Fox works, which will surely be useful in the future. Thank you very much for your help, and for an awesome recipe! Ugo June 01, 2012, at 03:26 AM

Checkbox with no option selected

I want to create a Fox form with a checkbox with multiple choices. I wrote the following code for the checkboxes:

(:input checkbox name=parameter[] value='First':)
(:input checkbox name=parameter[] value='Second':)
(:input checkbox name=parameter[] value='Third':)

In the template page, I have only the following: {$$parameter}

If the user checks one or more options, then all is fine and the options are added in the target page, separated by commas.
But if the user doesn't check any option at all, in the target page I see the variable name, {$$parameter}.
Is there any way to prevent the variable name from appearing if no check box is selected? Ugo May 23, 2012, at 03:07 PM

HansB: PmWiki versions 2.2.13 and earlier kept unset include/template variables. Do you run an older version of PmWiki or Fox? In PmWiki version 2.2.14 the default changed to suppress any display of template variable names when no value is posted. This behaviour can also be changed by setting $EnableUndefinedTemplateVars, see also PagelistVariables#EnableUndefinedTemplateVars.

Hans: I'm using pmwiki-2.2.37 and I only downloaded Fox yesterday. For the moment I solved the problem with
(:if !equal {$$parameter} "{$$$parameter}":){$$parameter}

but now I will try setting $EnableUndefinedTemplateVars. Thank you for your quick reply. Ugo May 23, 2012, at 04:19 PM

Update: setting $EnableUndefinedTemplateVars doesn't change anything in the target page. So I'll stick to the conditional markup to avoid displaying the variable name. Thanks for a great recipe. Ugo May 23, 2012, at 04:29 PM

Then I don't know what caused this behaviour in your case. How is it working with a test form like this:

(:linebreaks:)
(:foxmessages:)
(:fox test:)
(:foxtemplate "{$$parameter}":)
(:input checkbox name=parameter[] value='First':)
(:input checkbox name=parameter[] value='Second':)
(:input checkbox name=parameter[] value='Third':)
(:input submit post:)
(:foxend test:)
Hans: with your test form, it works fine! Obviously I need to get more experience with Fox, to understand its mechanism. Now I can use this test form to modify my form and get rid of the conditional, which is rather messy. Thank you very much for your support. Ugo May 24, 2012, at 05:29 AM

it also works with a call to a template, not just using the foxtemplate markup. Without seeing your template and the Fox form I cannot advise more. HansB

Hans: I merged your test form with my form (and the template), it all works perfectly now! Thank you! Ugo May 24, 2012, at 01:16 PM

Replace without a blank line

When i try to replace the content beetween two anchors (or two words), as in the fox form below, it creates a blank line beetwen the anchors. Is it normal ? And is there a way to have no blank line and no space beetwen the anchors ? Benji January 27, 2012, at 07:39 AM

(:fox sup foxaction=replace target={$FullName} put=marktomark mark=[[#a]] endmark=[[#B]]:)
(:foxtemplate "":)
(:input submit post "Supprimer":)
(:foxend sup:)

[[#A]]test[[#B]]

Result

[[#A]]

[[#B]]

Right now I am not sure why I added newline characters when doing a "mark to mark" replace, so i am unsure if this is a bug or feature! You can remove these by hacking fox.php: edit ca. line 866, replacing this line:

$text = substr_replace($text, "\n".$template."\n", $ipos, $ilen); break; }

with this:

$text = substr_replace($text, $template, $ipos, $ilen); break; }

You notice the "\n" newline characters are removed. Please let me know if anything breaks with this hack! It is specific to fox replacement mode "put=marktomark" - HansB February 02, 2012, at 03:38 PM

Ok. In fact, i just already did this on the fox.php, and it works, and for the moment i did not see any problems. Benji February 04, 2012, at 02:17 AM

changed now in fox.php - HansB February 21, 2012, at 05:50 AM


How to update PTVs on two different pages

I have a fox form that creates a new page based on a template, and sets various PTVs on that new page. But I would also like to update a PTV on the EditSource at the same time. Is this possible? I have tried several things already, including (:foxptv:), but I must be doing something wrong. Let's assume I have a ptv on the EditSource called "Status", that I would like to set to "Complete" upon submit... Is there a way to do that with foxptv, and if so, what is the syntax?
BTW, FOX is a wonderful cookbook!! Thanks! -Michael

To add content to Target1 using Template1 page and update a PTV ptv2 on Target2 please try something like this:

(:fox formA:)
(:foxadd target=Target1 template=Template1:)
(:foxptv Target2 ptvfields=ptv2:)
(:input submit post:)
(:foxend formA:)

i.e. you need to use foxadd and foxptv, not markup for adding content in the fox form directive. - HansB January 24, 2012, at 01:06 PM


I want to create a target pagename using the value from an input field

Can I do that with markup similar to this:

(:fox NewCustomerForm target={(pagename "Customers.{$$Cust_ID}")} redirect=1 ptvclear=1 template=FoxTemplates.CustomerNew:)
(:input submit post value="Create New Customer":)
!!Customer Information
||
||! ID||(:input text name=Cust_ID:) ||(ex. SmithDaniel)||
...

The following type of form works, but in the previous example I don't want the target auto-generated.

(:fox NewDistributionForm target="Distributions.{$:New_Distr_ID}" redirect=1 template=FoxTemplates.DistributionNew:)
(:input submit post value="Create New Distribution":)
!!Distribution Information
(:New_Distr_ID: DST{(serial Distributions DST)}:)
...

Try in example 1 changing the target to

target="{$$(pagename Customers.{$$Cust_ID})}"

The markup expression {(pagename ....)} gets evaluated when the form loads, while in this syntax: {$$(pagename ....)} it gets evaluated after the form is submitted, early on in Fox's processing, evaluating replacement variables. -HansB

That makes it work! Thanks again. You saved the day. - DannyB 2011-10-14 3:18 PM


Pursuit: Create a child page in a new window while creating a parent page. Or create a parent page with a link/button that would create a link, related child page.

I am trying to use pagetext variable values from one form while creating a new form in a new window. As I am creating a new project page with Proj_ID containing an ID string, I would like to pass the value of Proj_ID to a child fox template page. I need the ID passed so that the other page links back to the parent page. Currently I have to copy the new project ID and paste it into the child page. Here is the markup I'm using in the new project and Forms.DistributionNew is a fox form page. New projects are pages in a Projects group with distribution entries in a Distribution group.

%newwin% Click [[Forms.DistributionNew | HERE ]] for a new distribution entry in a new window or tab.

!!!Active list
(:pagelist group=Distributions link={$FullName} fmt=#projectdistrtable:)

I don't think I understand the problem. A Fox form allows creation of several pages at once, each created via its own template page, with several markup lines like (:foxadd TemplatePage=>TargetPage ... :) or (:foxadd template=TemplatePage target=TargetPage ... :). - HansB October 06, 2011, at 03:00 AM

Thanks for your response. I'm too used to a regular programming procedural orientation where data is passed to the next "step" rather than collected all at once and written to other pages. I'll rethink my form/multi-child-page creation procedure. - DannyB 2011-10-07 10:00 AM

If you want to use a two step process, you could have Proj_ID written as value of a PTV on the first page, then use that variable in the form or the template used which creates the second page. - HansB October 07, 2011, at 02:05 AM

Thanks for the suggestion. I do have the Proj_ID stored as a PTV on the first page. I still don't understand how the second page form knows about the first pagename to get the Proj_ID from it? Or are you saying I have the first form create the second page and store the Proj_ID in it? But I don't always need the second page. - DannyB 2011-10-10 10:56 AM

Could you include the form which creates a Distributions page into the Project page, instead of a link to the form? Then the form can use the Proj_ID PTV directly. If you wish, you could hide the form using the Toggle recipe, so the Create new distribution link will just show the form. The included form needs to be part of the Project template, and any variables in it may need protection from being evaluated when the New Project form gets submitted, by using a triple $$$ syntax (see Fox#template). Or use (:include Forms.DistributionNew:) as part of your ProjectNew template page. - HansB October 10, 2011, at 08:07 AM

That is what I had in the beginning and may go back to it using the new ideas you have given. I'm just getting a better feel for how this single form distributing to multiple pages

Talk page for the Fox recipe (users).