PDA

View Full Version : Can anybody give a hand with php running totals?


webgirl
08-04-2008, 11:38 PM
Hi I have a form that collects all the information I require except I am now wanting to develop it into a running total form, echo the information in a session and give a quote number, it emails to both me and the user the quote and asks if they are wanting to proceed to submit a deposit.
Now where I am needing to learn is how to calculate in php/javascript to get a running total. I have looked at several forums and there seems to be a problem with javascript in calculating on the fly if there are two or more of select menus or checkbox fields for different fields.

Any suggestions are welcome as I am ready to have a go....

davidj
08-05-2008, 05:52 AM
can you do a screenshot of your form and upload it so i can see

tell me which fields you want to calculate

webgirl
08-05-2008, 10:44 PM
Hi davidj
Thanks for the reply.
This is the page link: http://www.visnetmedia.com/quote.php
The fields I want to calculate are:
How many web pages? e.g.price 1, price 2, price 3 etc.
Do you want any add-ons (Special Features)? Contact Form
Photo Gallery
News/Articles
Site Map
Google Map
Domain Name 2 Years
Domain Hosting 1 Year

That is pretty much it.

davidj
08-06-2008, 04:41 AM
do these fields have a currency value

webgirl
08-06-2008, 06:35 AM
Hi davidj
Yes I would like them to have the $ currency. I haven't set up the value in the form as currency for example the drop down box is:
<select name="website" class="texta">

<option value="">Please Select Option</option>
<option value="1 page"<?php
if (isset($error) && $_POST['website'] == '1 page') { ?>
selected="selected"
<?php } ?>>1 Page</option>
<option value="1-3 pages"<?php
if (isset($error) && $_POST['website'] == '1-3 pages') { ?>
selected="selected"
<?php } ?>>1-3 Pages</option>
<option value="4-6 pages"<?php
if (isset($error) && $_POST['website'] == '4-6 pages') { ?>
selected="selected"
<?php } ?>>4-6 Pages</option>
<option value="over 6 pages"<?php
if (isset($error) && $_POST['website'] == 'over 6 pages') { ?>
selected="selected"
<?php } ?>>Over 6 Pages </option>
</select>


This is an email form to me.
Thanks for helping...

davidj
08-06-2008, 07:46 AM
sorry webgirl

please indicate which fields need calculating on

is this calculation performed on the fly or when the page loads

webgirl
08-06-2008, 11:56 PM
Hi davidj
Sorry - happy to start with the website drop down first to get the idea before starting on the addons checkboxes.
I would like to have a running total on the page with a button to ask if they want to proceed with the order. It will automatically send an email to them and me. So there will be a button to ask send this quote in an email and a button to ask to proceed the order, this goes to the cart for a deposit.
I have no problem with the cart and session only the calculation. This is the complete form without php - with only one button at present (send email):

<form name="option" id="option" method="post" action="">
<table width="600" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="right" valign="top"><span class="required">* </span>Your Name:&nbsp;
</td>
<td><input name="name" type="text" class="texta" id="name" value="" size="30" maxlength="50" /></td>
</tr>
<tr>
<td align="right" valign="top">&nbsp;</td>
<td> </td>
</tr>
<tr>
<td align="right" valign="top"><span class="required">* </span>Your Business Name:&nbsp; </td>
<td><input name="business" type="text" class="texta" id="business" value="" size="30" maxlength="50" /></td>
</tr>
<tr>
<td align="right" valign="top">&nbsp;</td>
<td> </td>
</tr>
<tr>
<td align="right" valign="top"><span class="required">* </span>Your Telephone Number:&nbsp;</td>
<td><input name="telephone" type="text" class="texta" id="telephone" value="" size="20" maxlength="20" /></td>
</tr>
<tr>
<td align="right" valign="top">&nbsp;</td>
<td> </td>
</tr>
<tr>
<td align="right" valign="top"><span class="required">* </span>Your Email Address:
&nbsp;</td>
<td><input name="email" type="text" class="texta" id="email" value="" size="30" maxlength="80" /></td>
</tr>
<tr>
<td align="right" valign="top">&nbsp;</td>
<td></td>
</tr>
<tr>
<td colspan="2" valign="top"><p><strong><em>How many website pages for example 1 only a home page or 1-3 could be home, contact us, thank you pages, 4-6 could be home, contact us, thank you, about us, prices, photo gallery. This is an example only and your business may need a different mix. </em></strong></p></td>
</tr>
<tr>
<td align="right" valign="top"><span class="required">* </span>How many web pages?&nbsp;
&nbsp; &nbsp;</td>
<td valign="top"><select name="website" class="texta">
<option value="">Please Select Option</option>
<option value="1 page">1 Page</option>
<option value="1-3 pages">1-3 Pages</option>
<option value="4-6 pages">4-6 Pages</option>
<option value="over 6 pages">Over 6 Pages </option>
</select></td>
</tr>
<tr>
<td align="right" valign="top">&nbsp;</td>
<td></td>
</tr>
<tr>
<td align="right" valign="top"><span class="required">* </span>Do you have your own images? &nbsp;</td>
<td><input name="images" type="radio" value="Yes"
/>
Yes
<input name="images" type="radio" value="No"
/>
No </td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td align="right" valign="top"><span class="required">* </span>Do you have a logo image? &nbsp;</td>
<td><input name="logo" type="radio" value="Yes"
/>
Yes
<input name="logo" type="radio" value="No"
/>
No </td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td align="right"><span class="required">*</span> Logo name: &nbsp;</td>
<td><input name="logoname" type="text" class="texta" id="logoname" value="" size="30" maxlength="50" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;&nbsp;</td>
</tr>
<tr>
<td colspan="2"><p><em><strong>Website colours for example - mostly white with dark purple, golden yellow and light grey. </strong></em></p></td>
</tr>
<tr>
<td align="right" valign="top"><span class="required">*</span> Web colours:&nbsp;</td>
<td valign="top"><input name="webcolours" type="text" class="texta" id="webcolours" value="" size="30" maxlength="80" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;&nbsp;</td>
</tr>
<tr>
<td colspan="2"><p><strong><em>If you know of any websites that you like the look of for your website please give us the names </em></strong></p></td>
</tr>
<tr>
<td align="right"> Website name 1:&nbsp; </td>
<td valign="top"><input name="webaddress1" type="text" class="texta" id="webaddress1" value="" size="30" maxlength="80" />
start with http://</td>
</tr>
<tr>
<td align="right">&nbsp;</td>
<td valign="top">&nbsp;&nbsp;</td>
</tr>
<tr>
<td align="right">Website name 2:&nbsp;</td>
<td><input name="webaddress2" type="text" class="texta" id="webaddress2" value="" size="30" maxlength="80" />
start with http://</td>
</tr>
<tr>
<td align="right">&nbsp;</td>
<td>&nbsp;&nbsp;</td>
</tr>
<tr>
<td colspan="2" valign="top"><strong class="red"><em>Do you want any add-ons (Special Features)?&nbsp;</em></strong></td>
</tr>
<tr>
<td width="41%" valign="top"><strong class="red"></strong></td>
<td width="59%"><p>
<input type="checkbox" name="addon[]" value="Contact Form" id="contactform"
/>
<label for="contactform">Contact Form</label>
</p>
<p>
<input type="checkbox" name="addon[]" value="Photo Gallery" id="photogallery"
/>
<label for="photogallery">Photo Gallery</label>
</p>
<p>
<input type="checkbox" name="addon[]" value="News/Articles" id="news"
/>
<label for="news">News/Articles</label>
</p>
<p>
<input type="checkbox" name="addon[]" value="Site Map" id="sitemap"
/>
<label for="sitemap">Site Map</label>
</p>
<p>
<input type="checkbox" name="addon[]" value="Google Map" id="googlemap"
/>
<label for="googlemap">Google Map</label>
</p>
<p>
<input type="checkbox" name="addon[]" value="Domain Name" id="domain_name"
/>
<label for="domain_name">Domain Name</label>
2 Years </p>
<p>
<input type="checkbox" name="addon[]" value="Domain Hosting" id="domain_hosting"
/>
<label for="domain_hosting">Domain Hosting 1 Year</label>
</p>
<p>&nbsp;</p></td>
</tr>
<tr>
<td colspan="2" valign="top"><p><em>If you want to get your own domain name and domain hosting yourself first we recommend using <a href="http://www.digitalpacific.com.au/affiliate/idevaffiliate.php?id=212_1">digitalpacific.com.au</a> <a href="http://www.digitalpacific.com.au/affiliate/idevaffiliate.php?id=212_1" target="_blank">Reliable Australian Web Hosting</a> - their service and prices are the best to offer. <br />
<br />
</em></p></td>
</tr>
<tr>
<td colspan="2" class="red"><p><em><span class="required">* </span>Extra notes and budget - <br />
also explain what type of business you have e.g. Friendly, business, professional, innovative, safe, funky, smart, fun, edgy, informative, corporate etc:&nbsp;</em></p></td>
</tr>
<tr>
<td><div align="right"><br />
<label> </label>
</div></td>
<td><textarea name="notes" id="notes" cols="30" rows="8"> </textarea></td>
</tr>
<tr>
<td>&nbsp;
</td>
<td>&nbsp;</td>
</tr>
<tr>
<td align="right" valign="top"><span class="required">* </span>Please Tell Us How You Found Us? &nbsp;
<label> </label></td>
<td valign="top"><select name="howhear" size="1" class="texta">
<option value="">Please Select Option</option>
<option value="google">Google</option>
<option value="yahoo">Yahoo</option>
<option value="othersearchengine">Other Search Engine </option>
<option value="magazine">Magazine</option>
<option value="salesrep">Sales Rep</option>
<option value="friend">Friend</option>
<option value="other">Other</option>
</select></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="orange"><div align="center"><em>Includes FREE - SEO, Search Engine Submission and Backend Administration. </em></div></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><label>
<input name="send" type="submit" class="searchbutton" id="send" value="Get A Free Quote" />
</label></td>
</tr>
</table>
</form>


Is that what you are asking for? Hope I have given enough information.
Thank you...

webgirl
08-10-2008, 07:45 AM
Hope somebody can help with this...
I have been having ago by using define() - didn't work and so now for the php I have this but I know it isn't calculating the fields:
For the website drop down the php part of the form is:
<select name="website" class="texta">
<option value="">Please Select Option</option>
<option value="1 page"<?php
if (isset($error) && $_POST['website'] == '1 page') { ?>
selected="selected"
<?php } ?>>1 Page</option>
<option value="1-3 pages"<?php
if (isset($error) && $_POST['website'] == '1-3 pages') { ?>
selected="selected"
<?php } ?>>1-3 Pages</option>
<option value="4-6 pages"<?php
if (isset($error) && $_POST['website'] == '4-6 pages') { ?>
selected="selected"
<?php } ?>>4-6 Pages</option>
<option value="over 6 pages"<?php
if (isset($error) && $_POST['website'] == 'over 6 pages') { ?>
selected="selected"
<?php } ?>>Over 6 Pages </option>
</select>

For the addons:

<input type="checkbox" name="addon[]" value="Contact Form" id="contactform"
<?php
$OK = isset($_POST['addon']) ? true : false;
if ($OK && isset($error) && in_array('Contact Form', $_POST['addon'])) { ?>
checked="checked"
<?php } ?>>
<label for="contactform">Contact Form</label>
</p>
<p>
<input type="checkbox" name="addon[]" value="Photo Gallery" id="photogallery"
<?php
if ($OK && isset($error) && in_array('Photo Gallery', $_POST['addon'])) { ?>
checked="checked"
<?php } ?>>
<label for="photogallery">Photo Gallery</label>
</p>
<p>
<input type="checkbox" name="addon[]" value="News/Articles" id="news"
<?php
if ($OK && isset($error) && in_array('News/Articles', $_POST['addon'])) { ?>
checked="checked"
<?php } ?>>
<label for="news">News/Articles</label>
</p>
<p>
<input type="checkbox" name="addon[]" value="Site Map" id="sitemap"
<?php
if ($OK && isset($error) && in_array('Site Map', $_POST['addon'])) { ?>
checked="checked"
<?php } ?>>
<label for="sitemap">Site Map</label>
</p>
<p>
<input type="checkbox" name="addon[]" value="Google Map" id="googlemap"
<?php
if ($OK && isset($error) && in_array('Google Map', $_POST['addon'])) { ?>
checked="checked"
<?php } ?>>
<label for="googlemap">Google Map</label>
</p>
<p>
<input type="checkbox" name="addon[]" value="Domain Name" id="domain_name"
<?php
if ($OK && isset($error) && in_array('Domain Name', $_POST['addon'])) { ?>
checked="checked"
<?php } ?>>
<label for="domain_name">Domain Name</label>
2 Years </p>
<p>
<input type="checkbox" name="addon[]" value="Domain Hosting" id="domain_hosting"
<?php
if ($OK && isset($error) && in_array('Domain Hosting', $_POST['addon'])) { ?>
checked="checked"
<?php } ?>>
<label for="domain_hosting">Domain Hosting 1 Year</label>
</p>


At the top of the validation part of the form I have:

$totalqty = $tquote + $quote;
$totalamount = number_format($totalamount, 2);
$website = $_POST['website'];
if (empty($website)) {
$error['website'] = 'Please select the size of your website';
}
if($_POST['website']=="1 page")
{
$tquote = 100;
}
if($_POST['website']=="1-3 pages")
{
$tquote = 330;
}
if($_POST['website']=="4-6 pages")
{
$tquote = 440;
}
if($_POST['website']=="over 6 pages")
{
$tquote = 660;
}
$addon = $_POST['addon'];
if($_POST['addon']=="Contact Form")
{
$quote = 15;
}
if($_POST['addon']=="Photo Gallery")
{
$quote = 95;
}
if($_POST['addon']=="News/Articles")
{
$quote = 150;
}
if($_POST['addon']=="Site Map")
{
$quote = 75;
}
if($_POST['addon']=="Google Map")
{
$quote = 55;
}
if($_POST['addon']=="Domain Name")
{
$quote = 45;
}
if($_POST['addon']=="Domain Hosting")
{
$quote = 90;
}


How can I get the sum amount of these?

webgirl
08-13-2008, 03:56 AM
Ok looks I have a solution for the select box and it works just need some ideas for the checkboxes to add value.
For anybody else that needs help with this - so far:

$website = trim($_POST['website']);
switch ( $website )
{
case "1 page" :
$cost = 110;
break;
case "1-3 pages" :
$cost = 330;
break;
case "4-6 pages" :
$cost = 440;
break;
case "over 6 pages" :
$cost = 660;
break;
}
$total = 0;
if (!empty($_POST['website']))
{
$total = $total+$cost;
}
if (empty($website)) {
$error['website'] = 'Please select the size of your website';
}

And next to select box:

<?php echo 'Web page cost is: $'. $total;
?>


I know the checkboxes are going to need to tally the lot. I found that javascript just wouldn't work with my php coding.