[pmwiki-devel] Page Vars - A Little Help?
Steven Leite
steven_leite at kitimat.net
Fri Mar 25 16:50:00 CDT 2011
Thanks to all of you that replied.
Eemeli Aro caught one small mistake which was that I had forgotten to
set $FmtPV as a *global *in my script.
Everyone was curious to know why I didn't use some other method within
my page text. The reason is simple (as implied by mere mention of
writing a script). The variables are being dynamically generated - the
PmForm has no way to know what the variables will be or what their
default values will be until my script has injected them in to the page
- hence cannot be placed directly in the wiki page. In fact, the entire
wiki page is dynamically generated by another recipe that I wrote. The
actual Wiki Page only has a simple line of code in it:
*(:order id=product_id title="Product Title" description="Longer product
description" price1="$15.00" price2="$25.00" shipping="$4.95"
other_option_variables="values":)*
Using that one line of code I'm able to populate the page with a very
elaborate product order form. The end result of the (:order:) directive
is actually what plants the (:pmform:) directive on the page (complete
with several dynamically created Page Vars that are now injected in to
the form when it's rendered!
This little problem of *PageVars *was actually a small piece of the
puzzle for a larger problem which I posted about a week ago which was
how I could "inject" my own form fileds in to a PmForm. I decided to
break the problem down in to smaller parts, hence my other recent posts:
Re: [pmwiki-devel] PmForm - Need a little help
Re: [pmwiki-devel] Working with uploads / attachments /
$UploadPrefixFmt
Re: [pmwiki-devel] Page Vars - A Little Help?
I finally have all the pieces I need to make this all work together!
Thanks again to everyone who replied. You all helped me work through
the logic, and eventually I was able to solve the problem.
For those that are curious, here's some end-result of my (test) coding
efforts which is actually working.
In my test script:
STEP 1 - My script
*my_function($args)
{
global $FmtPV;
$my_vars = ParseArgs($args);
if (isset($my_vars['price']))
{
// set page variable for 'price'
$price = $my_vars['price'];
$FmtPV['$price'] = "'$price'";
}
return "(:pmform orderform:)";
}*
Now that I have this working, I create my PmForm template in
Site.LocalTemplates. I am then able to set any number of page
variables (from my script) and I can generate customized forms with
pre-filled (dynamic) data using only the one PmForm template.
By using (:if:) statements in the PmForm template I can conditionally
include or exclude fields from my form.
Snippet / Example of a form template which may or may not include a form
field. This form has the following Page Var's defined: $product_id,
$product_image_url, $product_title and $product_description.
***[[#orderform]]
(:input default request=1:)
(:input pmform target={$$target} successpage={$$successpage} :)
(:template defaults successpage='Main/ThankYouForYourOrder' :)
(:input hidden product_id {$product_id}:)
(:input hidden product_image_url "{$product_image_url}":)
(:if !equal {$product_image_url} '':)
Attach:{$Group}/{$Name}/{$product_id}.jpg
(:ifend:)
!{$product_title}
{$product_description}
...
(:input submit name=post value='$[Send]':)
(:input end:)
[[#orderformend]]
*You can see I've made extensive use of {$page_vars} here. All of these
have been transplanted on the page from my script which was triggered
before the (:pmform:) directive. With the use of (:if:) statements in
the form template itself, I can check to see if those variables are set
(or not), and decide if I should display them (or not).
I was also able to use PmForms email option to send a HTML version of
the completed order form complete with a picture of the product and the
company logo. This was accomplished by adding a few extra lines in my
config.php file to anable text/html e-mails:
*$PmFormMailHeaders = 'MIME-Version: 1.0' . "\r\n";
$PmFormMailHeaders .= 'Content-type: text/html; charset=iso-8859-1' .
"\r\n";*
Very please with the final product. Ones I get all the bugs worked out,
and proper documentation done I'll upload it to the Cookbook area.
Again, thank to all who replied! Although some responses were not as
helpful as others, all responses were *equally *appreciated!
Best Regards,
Steven Leite
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.pmichaud.com/pipermail/pmwiki-devel/attachments/20110325/0ec60f71/attachment.html>
More information about the pmwiki-devel
mailing list