PDA

View Full Version : Leaving out fields in a template



tobyw
26-Jul-2007, 07:21 AM
Hi. I have an obscure challenge. I am using formmail to send the contents of an order form. The problem I have is that the order form lists every product by name/description even if the quantity ordered is nil. What I want is the ability to suppress the inclusion of the product name, and some other fields, if the quantity ordered is 0 or null - so the e-mail only contains the product details (plus quantity, price and line total) for products that have been ordered.

I don't mind if the template is text or HTML.

I reckon I could do it if it was possible to use an HTML template which runs PHP, but I doubt this can be done....?

Any other ideas?

Many thanks

===Toby===

russellr
26-Jul-2007, 07:59 AM
Hi,

There's no way to send the fields to a template that runs PHP so that the PHP can work on the fields. The PHP executes to produce HTML, and then FormMail does the field substitution in the HTML.

We do have an easy solution though - Advanced Templates.

To get the Advanced Templates feature you need to purchase the FormMail Computation Module, which costs US$195. Later this year a cheap rental option should be available for this product.

tobyw
26-Jul-2007, 08:12 AM
Hi Russell. Thanks for the reply.


There's no way to send the fields to a template that runs PHP so that the PHP can work on the fields. The PHP executes to produce HTML, and then FormMail does the field substitution in the HTML

- isn't that what I want? I could use PHP to create an HTML template that omitted the code for including certain fields which FormMail would then do the appropriate field substitution on. Or am I missing something?

Thanks

===Toby===

russellr
26-Jul-2007, 08:25 AM
Hi,

No, what you want is to perform some logic depending on whether a field has some value ("if qty = 0, don't send this HTML").

A template written in PHP doesn't get to see the field values so it cannot perform the logic.

In other words, the field substitution happens too late.

Remember, FormMail replaces "$realname", "$email", "$qty" in the HTML with those field values. Those strings should appear in the HTML output of the template and then get substituted for the field values.

tobyw
26-Jul-2007, 08:47 AM
A template written in PHP doesn't get to see the field values so it cannot perform the logic.

In other words, the field substitution happens too late.
- Ah, yes, of course. Sorry to be so dumb!

Thanks for your help. I'll have a look at Advanced Templates.

===Toby===

russellr
26-Jul-2007, 09:05 AM
Hi,


Sorry to be so dumb!
You're not dumb, it's subtle and complicated. :)

There's almost not documentation about Advanced Templates.

But they are really simple. You get to do this in your templates:



<if iAppleQty>
<p>You ordered some apples.</p>
</if>

Of course, you'd put lots of stuff between the <if> and the </if>.

The Computation Module also gives you computations. You can see these work here:
http://www.tectite.com/samples/orderform.htm

You can also open the folder/directory:
http://www.tectite.com/samples

and download the HTML (orderform.htm contains the computations) including the Advanced Template (orderform2.htm).

If you go ahead and buy the Computation Module, we provide you with 3 months support and we'll help you write your computations etc.

The lack of documentation is annoying, but the product is well tested and stable. It's just early days for it feature-wise, so we need to get some things done before we release it with full documentation.

tobyw
26-Jul-2007, 09:10 AM
Thanks for that Russell. I just bought it so your post will be most helpful!

===Toby===