PDA

View Full Version : Ability to manipulate variables in php templates during form process



schwim
19-Apr-2006, 12:46 AM
Hi there,

I'm attempting to set up a multi-page form for a friend that makes wooden signs. He'd like a form that gets all of the required information from the user(which is a lot; board length is calculated from the number of characters they want, whether the edges are routed, Letter and board height). Each of these options changes the price. What I'm trying to do is to set up a form that during the process, would calculate these changes and at the end of the form display a paypal button with the calculated cost being sent in the PayPal link. They get to the end of the form and simply click the payment button and they're done.

To do this, I think I need to be able to run statements on the variables from the previous page(s). I'm wondering if this is possible. I've tried simply printing the variables, and although it works with an html template, it does not in .php.

My question is this: Is there a way to do this with .php templates? IF NOT, could I maybe direct them to a final thank you page in HTML that holds the variables, and then they click a button that takes them to a PHP page that calculates the cost?

I know that's very confusing, but I hope you see what I mean:

They enter their personal info in form page one

FormMail takes over and gets the rest of the information

The final formmail page doesn't say that the process is over, but instead tells them to click this button to calculate the cost
that link takes them to a php page that CAN calculate cost and provide a link to PayPal.

thanks,
json

russellr
19-Apr-2006, 01:45 AM
Hi,

The problem is that templates (Multipage forms and error templates) are processed by FormMail (and FMBadHandler) just before sending to the browser.

In the case of using a PHP script as a template (which is fine to do) PHP doesn't see the $name expansion - this is done *after* PHP has output the HTML. Therefore PHP for templates doesn't work for calculations (it's for dynamic websites, like ours).

So, there are two ways to go:

Use our FormMail Computation Module. It works great and is out of Beta test. But, it's early days for this product and we haven't completed the documentation yet. Most customers are using this for GeoIP (http://www.tectite.com/geoip.php) support.
If you're comfortable with writing PHP, then you can use a simple technique. Write your PHP script which then includes "formmail.php" at the bottom. Your PHP can grab the submitted fields and perform computations, creating other fields in the process. FormMail doesn't know the difference and this technique works well (we've used it for several recent development contracts).For option 1, you'll need to buy (https://secure.rootsoftware.com/~tectite/newonline2w.php) the computation module and 12 months support. In this case, we'll help you write the computation code as part of the support contract.

For option 2, you can just get started. If you're having difficulty then you'll need to purchase support to get answers.

Option 2 is cheaper (especially if you can figure it all out yourself), but it's more complicated to write solid PHP code than it is to use the FormMail Computation Module.

Here's a sample of using the FormMail Computation Module (you just add hidden fields to your form):


<input type="hidden" name="fmcompute1" value="
import int size,type;
export float cost;

if (type == 1)
{
cost = 0.50; /* 50 cents per length */
}
elseif (type == 2)
{
cost = 0.75; /* 75 cents per length */
}
cost = cost * size;
" />

schwim
19-Apr-2006, 02:46 AM
Hi there Russell,

I'm not very good with php, but I can muddle, and I can also pay for your help :). I'm wary to use the computation module, simply because I'm befuddled enough with the options available to me with the formmail script. I would never be able to get through the coding necessary to do it. Besides I'm doing this sans fee for a friend :), so I'm not up to spending too much dough.

That being said, I'll be purchasing a support contract tonight and you'll almost immediately hear from me concerning how to implement it via an include.

thank you very much for the time you've taken so far in halping me. It's greatly appreciated.

thanks,
json