我做了类似的事情:
devis2.php
<script type="text/javascript" src="quote_validation2.js"></script>
<?php
$ddcount = 1;
foreach ($_POST as $key => $value) {
$$key = $value;
}
If (isset($_POST['garment_type']) && $ddcount == 1) {
$post_to = "devis2-resultats.php";
$ddcount = $ddcount + 1;
} Else {
$post_to = "devis2.php";
}
?>
<div style="float:right; display: block;"><a href="devis2.php"><img style="border: none;" border="0" src="images/quote-again.gif" width="120" height="16" /></a></div><br/><br/>
<form name="instantquote" onSubmit="return validator(this)" method="post" action="<?php echo $post_to; ?>">
Au bac:<br/><select multiple size="3" name="garment_type" class="quoteFields" tabindex="1">
<?php
If (isset($_POST['garment_type'])) {
echo "<option value=\"$garment_type\" selected>$garment_type</option> \n";
} Else {
echo "<option value=\"0\" selected>Choisir un soin</option> \n";
}
?>
<option value="soin1">soin1</option>
<option value="soin2">soin2</option>
</select><br/>Longueur des cheveux*:<br/>
<select name="colors_back" class="quoteFields" tabindex="5" size="1" onChange="Javascript:document.instantquote.submit()" >
<?php
If (isset($_POST['colors_back'])) {
echo "<option value=\"$colors_back\" selected>$colors_back</option> \n";
} Else {
echo "<option value=\"0\" selected>Choisir une longueur</option> \n";
}
?>
<option value="+ de 25 cm">+ de 25 cm</option>
<option value="- de 25 cm">- de 25 cm</option>
</select>
<input type="hidden" name="ddcount" value="<?php echo $ddcount; ?>">
<br/><br/><input type="submit" value="Obtenir votre devis" name="quote" class="quoteSubmit" tabindex="20">
</form>
devis2-resultats.php
<?php
foreach ($_POST as $key => $value) {
$$key = $value;
}
include("quote-prices2.php");
?>
<br/><br/><b>Au bac:</b> <?php echo $garment_type; ?><br/><br/>
<?php
If (!isset($_POST['ind_numbers'])) {
} Else {
?>
Individual Numbers:<?php echo $ind_numbers; ?><br/><br/>
<?php
}
If (!isset($_POST['ind_names'])) {
} Else {
?>
Individual Names: <?php echo $ind_names; ?><br/><br/>
<?php
}
If (!empty($email)) { ?>
<br/><br/><b>Envoyé à:</b> <?php echo $email; ?><br/><br/>
<?php
}
?>
<br/><br/><div style="font-size:16px; background-color:#fff; color:#bf3d71;"> <b>Total:</b> <?php $dectotal = sprintf('%0.2f', $total); echo $dectotal; ?> $</div><br/><br/><br>
引号prices2.php
<?php
// INCOMING VARIABLES FOR PROCESSING: garment_type, garment_color, quantity, colors_front, colors_back, ind_numbers, ind_names
// GARMENT TYPE PRICE
$flash_charge = 0;
switch ($garment_type) {
case "soin1":
$price_garment_type = 6.00;
break;
case "soin2":
$price_garment_typea = 7.00;
break;
}
if ($_POST['garment_type'] === 'soin2') {
switch ($colors_back) {
case "+ de 25 cm":
$price_garment_typea = $price_garment_typea + 50;
break;
}}
$total_garment_pricing = $price_garment_type + $price_garment_typea;
$total_additionals = $total_garment_pricing;
$total = $total_garment_pricing + $total_additionals;
$per_garment_price = $total/2;
$total = $total/2;
?>
**quote_validation2.js**
function validator(form) {
if (form.colors_back.value == 0) {
alert("Vous devez sélectionner une longueur de cheveux.");
return false;
}
return true;
}
function CalcKeyCode(aChar) {
var character = aChar.substring(0,1);
var code = aChar.charCodeAt(0);
return code;
}
function checkNumber(val) {
var strPass = val.value;
var strLength = strPass.length;
var lchar = val.value.charAt((strLength) - 1);
var cCode = CalcKeyCode(lchar);
/* Check if the keyed in character is a number
do you want alphabetic UPPERCASE only ?
or lower case only just check their respective
codes and replace the 48 and 57 */
if (cCode < 48 || cCode > 57 ) {
var myNumber = val.value.substring(0, (strLength) - 1);
val.value = myNumber;
}
return false;
}
我在php开发方面非常糟糕。此时,如果我选择soin1 & soin2
,则仅显示一个价格。 soin1 = 6 & soin2 = 7
如果他们都被选中,那么我想获得13。当然,如果soin1,soin2&amp;选择+ de 25 cm我想得到63。问题是如何进行多项选择以获得soin1 & soin2
的添加。请参阅脚本here。