[pmwiki-devel] Accessing field values in PmForms

DaveG pmwiki at solidgone.com
Tue Feb 10 20:04:35 CST 2009


I'm using a PmForm to save values to a page. Is there a way to reference 
the field values from within the dataform? Specifically I'd like to be 
able to reference the field values of a form reloaded due to an error, 
when using.
   (:input default request=1 :)

*Background*
I'm saving PmForm field values to a page. On the page header I include 
the directive:
   (:pmform test:)

Because the field values are stored on the page, and the form is 
rendered in the header I can reference the field values using:
   {$:field_name:)

I store the field values along with additional information I'd like to 
strip out, so I do some processing:
   (:input text $:email size=25 value="{(substr "{$:email}" 1 3)}":)

Which works, because the fields are on the page.

However, when the page is re-displayed due to a PmForm triggered error 
(like title being empty in the sample below), the field displays the 
field value, not the new value re-displayed from PmForms.
1] Save the page to get some values.
2] Now with values in the form, change the Email field to "retryemail".
3] Blank out the Title -- this will raise a PmForm error.
4] Notice the original value is in Email (it's picked up from the page 
variable set in [1]).

what I'd like to do is replace the use of the field variable {$:email}, 
and somehow reference the value sent back to the form by PmForms.


*Sample*
In the sample below, on the email field is a contrived example, but 
shows the kind of thing I'm trying to do. Test page is:
   http://wiki.solidgone.org/Test/FormData

If the field processing is not possible from the dataform, is it 
possible to perform functions as immediately after the form is 
processed, but before it's displayed -- perhaps queue something up 
post-PmForm processing, and manipulate the variables there?

  ~ ~ Dave

-----
Directive on page Test.FormData:
   (:pmform test:)

config.sys
   $PmForm['test'] = 'form=Test.PmForms#dataform fmt=Test.PmForms#datapost';
[@
[[#dataform]]
   value of email is {$:email}

In page Test/PmForms:
(:input pmform target=test:)
(:input default source="Test/FormData" :)
(:input default request=1 :)
(:messages:)
|| Name:||(:input text $:name size=25 :) ||
|| Email:||(:input text $:email size=25 value="{(substr "{$:email}" 1 
3)}":) ||
|| Title:||(:input text $:title size=25 :) ||
(:input submit :)
(:input end:)
[[#dataformend]]
@]

[@
[[#datapost]]
(:template defaults saveto="Test/FormData":)
(:template require $:title errmsg="$[Title is required]":)
(:template defaults savevars=$:name,$:email,$:title :)
[[#datapostend]]
@]




More information about the pmwiki-devel mailing list