Forums

Some info not submitted in received mail

lidosofia 24 Aug, 2008
hi,

i finished my form with the calculating stuff...
all work but the area of total isnt submitted in the mail i receive...

The form:

<table> 
<tr><td colspan="2"> Zimbra Bestelformulier </td></tr> 
<tr><td><font color=""><b>Naam</b>:</font></td>
<td><input name="Naam" type="text" id="Naam" size="40" maxlength="40" value="<?php $user = &JFactory::getUser();echo $user->name;?>" ></td></tr> 
<tr><td><font color=""><b>Adres</b>:</font></td>
<td><input type="text" name="adres" maxlength="30" value="" style="width: 200px"></td></tr> 
<tr><td><font color=""><b>Woonplaats</b>:</font></td>
<td><input type="text" name="woonplaats" maxlength="30" value="" style="width: 200px"></td></tr>
<tr><td><font color=""><b>Postcode</b>:</font></td>
<td><input type="text" name="postcode" maxlength="20" value="" style="width: 200px"></td></tr> 
<tr><td><font color=""><b>Telefoon</b>:</font></td>
<td><input type="text" name="telefoon" maxlength="20" value="" style="width: 200px"></td></tr> 
<tr><td><font color=""><b>Email</b>:</font></td>
<td><input name="email" type="text" id="email" size="30" maxlength="30" value="<?php $user = &JFactory::getUser();echo $user->email;?>" ></td></tr>
<tr><TD ALIGN="CENTER">Aantal Accounts:</TD>
<td>Zimbra</TD></TR>
<tr><td>
<input type="text" name="PROD_SP_4.50" size=3 maxlength=3 onChange="Calculatetotal(this.form)" style="width: 52px"></TD>
<td>Prijs per account € 4.50</TD></TR>
<tr><td>Totaal:<BR></TD><td><input type=text  name=total size=10 onFocus="this.form.elements[0].focus()"> </TD>
<tr><td><font color=""><b>Uw website</b>: http://</font></td><td>
<input type="text" name="onderwerp" maxlength="30" value="" style="width: 200px"></td></tr> 
<tr><td valign=top><b>Opmerking</b>:</td>
<td><textarea name="bericht" class="" cols="30" rows="4"></textarea></td></tr> 
<tr><td></td><td><input type="submit" name="verzenden" value="Verzenden"></td></tr> 
</table>



The part that calculates and should put the result in mail mail is this one:
<input type="text" name="PROD_SP_4.50" size=3 maxlength=3 onChange="Calculatetotal(this.form)" style="width: 52px">

In the mail all info shows ,but as for the product,that only shows : PROD_SP_4.50 ,but not the total ammount.

This is javascript part:


function CalculateTotal(frm) {
  var order_total = 0
  for (var i=0; i < frm.elements.length; ++i) {
    form_field = frm.elements[i]
    form_name = form_field.name
    if (form_name.substring(0,4) == "PROD") {
      item_price = parseFloat(form_name.substring(form_name.lastIndexOf("_") + 1))
      item_quantity = parseInt(form_field.value)
      if (item_quantity >= 0) {
        order_total += item_quantity * item_price
      }
    }
  }
  frm.TOTAL.value = round_decimals(order_total, 2)
}
function round_decimals(original_number, decimals) {
  var result1 = original_number * Math.pow(10, decimals)
  var result2 = Math.round(result1)
  var result3 = result2 / Math.pow(10, decimals)
  return pad_with_zeros(result3, decimals)
}
function pad_with_zeros(rounded_value, decimal_places) {
  var value_string = rounded_value.toString()
  var decimal_location = value_string.indexOf(".")
  if (decimal_location == -1) {
    decimal_part_length = 0
    value_string += decimal_places > 0 ? "." : ""
  }
  else {
    decimal_part_length = value_string.length - decimal_location - 1
  }
  var pad_total = decimal_places - decimal_part_length
  if (pad_total > 0) {
    for (var counter = 1; counter <= pad_total; counter++) 
      value_string += "0"
    }
  return value_string
}


Last question i have is, as you can see the PROD_SP_4.50 is string to used as product and also used as PROD in the javascript part.
My product should be called zimbra,but as soon as i change the names the calculating doesnt work anymore...
The product costs 4.50,so if you type 10 x the total is 45,00 ...but that isnt submitted in the form...
A bit weird,am i doing something wrong ?
GreyHead 25 Aug, 2008
Hi lidosofia,

As far as I can see the total is calculated in the 'total' field:
<input type=text  name=total size=10 onFocus="this.form.elements[0].focus()">

if you add quotes round the attribute values - specifically the 'name' attribute - then it should be reported correctly; ChronoForms uses the quotes to parse the inputs and identify them.
<input type="text"  name="total" size="10" onFocus="this.form.elements[0].focus()">


The JavaScript uses the PROD prefix to identify the product fields. You could change this but probably simplest to name the field PROD_zimbra_4.50

Bob
lidosofia 25 Aug, 2008
Hi, that indeed worked..😀 ,thanks...
but i cant seem to get it changed so that the names pased..
in the mail i get :

PROD_zimbra_4.50
TOTAL 153.00

So it shows TOTAL instead of Total. , so all capital.
If i change it to Total then the count doesnt work anymore...(weird)

another thing,it shows the total in the mail but not the how many.
if i choose 10 x , then its 10 x 4.50 which is 45.00.
but in the mail i dont see the 10.

any way to solve all this ?
This topic is locked and no more replies can be posted.