Hello everyone,

I'm having one annoying problem with a script I didn't even write.
First of all, let me just point out the issue;

If you goto this address (site is in french): LINK
You'll notice that it's a dynamic calculator, if you choose "individual" and click next, it'll show you just 1 row but if you choose "family of two, three or more" it'll show you extra rows depending on the number you've picked.

What I wanna do here is IF the user chooses "family of two" or more, to separate the table in the next step by making the rows "Age" and "NSSF" the only variable fields while when he selects the "Class Type" for one of the family, it should be applied to all the rest at once.

I hope I wasn't too confusing in this.

For example, if I choose "family of 3" and click next, the next table should be split into 2, first the user has to:

- "Class Type" which will be selected only once but applied to the 3 persons in the family.
- "Couverture Ambulatoire"
- "Couverture M├ędicament "
- "Couverture Visites M├ędicales"

After the user finishes making his selection, he should then find another table below where he'll be able to select the "Age Range" and "NSSF" for each of the 3 persons separately. I can't be any clearer than this, I did my best

Anyway, here is the code which is all found in 1 single file. (attached below policy.php.txt)

Help is pretty much appreciated... thanks.
__________________

Attachments
$step = $_POST["step"];

if($_POST['sendmail']){
        
        $amnt= $_POST['amnt'];
        $amnt_amb = $_POST['amnt_amb'];
        $amnt_med = $_POST['amnt_med'];
        $amnt_doc = $_POST['amnt_doc'];
        $sum = $_POST['sum'];
        $counter = $_POST['nb'];
        $total = $_POST['total'];
        $nom = $_POST["nom"];
        $prenom = $_POST["prenom"];
        $phone = $_POST["phone"];
        
        
        $table ='<table align="center" cellpadding="3" cellspacing="0" border="1">
                    <tr id="policyheader">
                        <td id="policytd">#</td>
                        <td id="policytd">Montant Police(US$)</td>                        
                        <td id="policytd">Couverture Ambulatoire (US$)</td>
                        <td id="policytd">Couverture M&eacute;dicament (US$)</td>
                        <td id="policytd">Couverture Visites M&eacute;dicales (US$)</td>
                        <td id="policytd">Total Police (US$)</td>
                    </tr>';
        
        ksort($counter);
        foreach ($counter as $nb=>$data){
            
            $table.= "<tr>
                    <td id='policytd'>".number_format($nb,2,'.',',')."</td>
                    <td id='policytd'>".number_format(($amnt[$nb]?$amnt[$nb]:" "),2,'.',',')."</td>
                    <td id='policytd'>".number_format(($amnt_amb[$nb]?$amnt_amb[$nb]:" "),2,'.',',')."</td>
                    <td id='policytd'>".number_format(($amnt_med[$nb]?$amnt_med[$nb]:" "),2,'.',',')."</td>
                    <td id='policytd'>".number_format(($amnt_doc[$nb]?$amnt_doc[$nb]:" "),2,'.',',')."</td>
                    <td id='policytd'>".number_format($sum[$nb],2,'.',',')."</td>
                    
            </tr>";    
            
            
            
        }
        $table.= "<tr>
                <td align='right' colspan='5' id='policytd'><b> &nbsp;&nbsp;&nbsp; Total des primes:</b></td>
                <td id='policytd'><b>".number_format($total,2,'.',',')."</b></td>
         </tr>
         ";
    
        $table.= "</table>";
        
        $table.= "<br>Nom : $nom <br>prenom : $prenom <br>Phone : $phone</center>";
        
        
        
        $headers  = "MIME-Version: 1.0\r\n";
        $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
        
        /* additional headers */
        $headers .= "From: Axa Middle East <mail@mail.com>\r\n";

        //mail("mail@mail.com","Calculez vos primes d'assurances medicales ","$table",$headers);
        mail("mail@mail.com","Calculez vos primes d'assurances medicales ","$table",$headers);
    header("Location:sent.html");

        exit;
    }

if(!$step){

    ?>
        <html>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>.:AXA:.</title>
    <link href="styl.css" rel="stylesheet" type="text/css" />
    
    </head>
    <body>
    <script language="JavaScript">

    function checkVar(form)
    {
        
        nb_family_id = form.nb_family_id.value;
        
        if(nb_family_id=="")
        {
            alert("Choisissez le nombre de personne que vous dsirez assurer.");
            return false;
        }
        
        
        else return true;
    }
    
    </script>

    <form method="post" name="frm1" enctype="multipart/form-data" onSubmit="return checkVar(this);">
    <table>
            <tr>
                <td id="maintable">
                    <table width="100%" cellpadding="6" cellspacing="6">
                        <tr>
                            <td colspan="3" width="100%" id="header" style="font-family:tahoma; font-size:14px">
                            <strong>Assurances M&eacute;dicales</strong></td>
                        </tr>
                        <tr>
                            <td style="font-size:12px; font-family:tahoma" width="65%">
                            Combien de personne(s) voulez-vous assurer?                            </td>
                            <td>
                                    <?
                                        $query="select id,nb_family from family_type order by id";
                                        
                                        echo "<center>";
                                        comboBox($query,"nb_family_id",null,true);
                                        
                                        ?>
                            </td>
                            <td rowspan="3" valign="top"> <img src="6.gif"/></td>
                        </tr>
                        
                        <tr>
                            <td colspan="2" align="left">            
                                    <input type="hidden" value="1" name="step"/>
                                    <input type="submit" value="&Eacute;tape suivante" name="sbm"/></td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>

        
    </table>

    </center>
    <?  
    if(!$step){echo "<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />";}
    ?>
    
    </form>
    
    </body>
    
    </html>    
    <?
    exit();
}
if($step==2){
    //printR($_POST);        
    $age_range_id = $_POST["age_range_id"];
    $class_type_id = $_POST["class_type_id"];
    $nssf = $_POST["nssf"];
    $amb = $_POST["amb"];
    $med = $_POST["med"];
    $doc = $_POST["doc"];
    $counter = $_POST["counter"];
    $family_type_id = $_POST["family_nb"];
    
    
    $policy_title=id2fields("family_type","nb_family","id=$family_type_id"); 
    
    
    
    ?>

    
        
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <link href="styl.css" rel="stylesheet" type="text/css" />
    <script language="JavaScript">

    function checkVar2(form)
    {
        
        nom = form.nom.value;
        prenom = form.prenom.value;
        phone = form.phone.value;
        
        if(nom=="")
        {
            alert("Veuillez entrez votre nom.");
            return false;
        }
        else if(prenom=="")
        {
            alert("Veuillez entrez votre prnom.");
            return false;
        }
        else if(phone=="")
        {
            alert("Veuillez entrez votre numro de cellulaire.");
            return false;
        }
        
        
            else return true;
    }
    
    </script>
    </head>
    
    <form method="post" name="frm" enctype="multipart/form-data" onSubmit="return checkVar2(this);">
    
    <?
    echo "<p  style='font-size: 8pt; line-height:11pt; font-family:tahoma'>Les primes ci-dessous sont bas&eacute;es sur une assurance m&eacute;dicale - <b>$policy_title</b>.</p>";
    
    ?>
    
    <center>
    <table align="center" cellpadding="3" cellspacing="0" id="policytable">
        <tr id="policyheader">
            <td id="policytd" style="font-size: 10pt; line-height:11pt;  font-family:tahoma;">#</td>
            <td id="policytd" style="font-size: 10pt; line-height:11pt;  font-family:tahoma;">Montant Police(US$)</td>                        
            <td id="policytd" style="font-size: 10pt; line-height:11pt;  font-family:tahoma;">Couverture Ambulatoire (US$)</td>
            <td id="policytd" style="font-size: 10pt; line-height:11pt;  font-family:tahoma;">Couverture M&eacute;dicament (US$)</td>
            <td id="policytd" style="font-size: 10pt; line-height:11pt;  font-family:tahoma;">Couverture Visites M&eacute;dicales (US$)</td>
            <td id="policytd" style="font-size: 10pt; line-height:11pt;  font-family:tahoma;">Total Police (US$)</td>
        </tr>
    
    
    <?
    ksort($counter);
    foreach ($counter as $nb=>$data){
        
        //echo $age_range_id[$nb].'--'.$class_type_id[$nb].'--'.$nssf[$nb].'--'.$amb[$nb].'--'.$med[$nb].'--'.$doc[$nb].' ||||||| ';
        
        if((!$age_range_id[$nb])||(!$class_type_id[$nb]))continue;
        if($nssf[$nb]=="on")$add="and nssf=1";
        else $add="and nssf=0";
        
        if($amb[$nb]=="on")$get_amount_amb=id2fields("amb_plan","amount","family_type_id=$family_type_id and age_range_id =".$age_range_id[$nb]."");
        if($med[$nb]=="on")$get_amount_med=id2fields("pre_med_plan","amount","family_type_id=$family_type_id and age_range_id =".$age_range_id[$nb]."");
        if($doc[$nb]=="on")$get_amount_doc=id2fields("doc_plan","amount","family_type_id=$family_type_id and age_range_id =".$age_range_id[$nb]."");
    
        
        if($class_type_id[$nb]<>5){ // NO class SP
        
            $get_amount=id2fields("policy","amount",
                "age_range_id=".$age_range_id[$nb]." and class_type_id=".$class_type_id[$nb]." and family_type_id=$family_type_id $add");
        
        }
        else { // Class SP
            
            $get_amount=id2fields("policy","amount",
                    "age_range_id=".$age_range_id[$nb]." and class_type_id=".$class_type_id[$nb]." $add");

        }
        $sum_amount=$get_amount+$get_amount_amb+$get_amount_med+$get_amount_doc;    
        /*echo "<b>".($get_amount?$get_amount:"NaN").($get_amount_amb?"- $get_amount_amb ":"").($get_amount_med?" - $get_amount_med ":"").($get_amount_doc?" - $get_amount_doc total : ----> $sum_amount ":"")."</b>";
            echo "<br>";*/
            
        echo "<tr>
                    <td id='policytd' style='font-size: 10pt; line-height:11pt;  font-family:tahoma;'>".$nb."</td>
                    <td id='policytd' style='font-size: 10pt; line-height:11pt;  font-family:tahoma;'>".($get_amount?number_format($get_amount,2,'.',','):"NAN")."</td>
                    <td id='policytd' style='font-size: 10pt; line-height:11pt;  font-fam

by clicking to the mentioned URL, we get:
Authorization Required

To make dynamic textfields, you need to ask,

how many person: ________  submit ...

You can then dynamically create inputs and select boxes to get the further categories.

1th Age ___  , Name _____
2th Age ___  , Name _____
3th Age ___  , Name _____
Submit
1th Age 5  , Name xxxx , 25% escompte
2th Age 36  , Name yyyy ,  
3th Age 77  , Name vvvv , 25% escompte
Total:   __ euro
Submit

on submit, you check the ages, if its under X , you won't ask. If these categories comes from a table, you need to set age ranges for each entry, or set aage categories for easier maintenance.
Based on the person age, you can get the available options.

Sorry I left it the username and password out

user: axa
password: guest

I appreciate you taking the time to look into this. If you check the attached txt file (policy.php.txt) you'll see that everything you've mentioned above is already done but what I'm looking for is to transform the whole table into something else which is kinda hard for me to do coz I don't exactly understand how the previous developer did this.

This article has been dead for over six months. Start a new discussion instead.