I have an order form that is quite complex where you can order products form radio buttons.
I also have a text box where the price gets calculated live on the page depeding on what you are selecting.
This is done by using this script
<script type="text/javascript">
jQuery(document).ready(function($){
var frm = document.forms.myForm;
frm.onchange = function(e) {
var tot = 0;
for( var i = 0, l = frm.elements.length; i < l; i++ ) {
if( frm.elements[i].checked ) {
tot += parseFloat( frm.elements[i].getAttribute('data-price') );
}
}
document.getElementById('total').value = ( tot.toFixed(2) );
}
})
</script>
The box is here
<input id="total" name="total2" class="total-box" type="text">
But for some reason the info is not being added into the mail that gets sent, everything else gets sent fine.
In my mail script I have
$total2 = $_REQUEST['total2'] ;
and
<tr><td style="border-bottom:1px solid #7e7e7e;">Price</td><td style="border-bottom:1px solid #7e7e7e;">'.$total2.' </td></tr>
Any Ideas?
If you use javascript the value of the input field will not be set for the server $_POST data. So you are looking for some kind of serialization (i.e javascript that takes all the input values and sends them through $_POST, you could do it manually but its tedious)
If you want to stick to pure javascript: http://code.google.com/p/form-serialize/ might help out. Otherwise look at some framework and serialize(), most frameworks have it implemented as it is used quite often.
My suggestion would be to recreate your price generation script in PHP aswel, so you just submit which form buttons have been pressed (which you don’t need serialize for) and then just get the price from that on the backend. A lot safer too!