Questionnaire avec restriction en php

Fermé
christophe.therrien Messages postés 102 Date d'inscription lundi 25 mai 2009 Statut Membre Dernière intervention 9 juin 2010 - 27 mai 2009 à 18:40
christophe.therrien Messages postés 102 Date d'inscription lundi 25 mai 2009 Statut Membre Dernière intervention 9 juin 2010 - 28 mai 2009 à 16:36
Bonjour, j'aimerais savoir comment mettre des restrictions (else,elseif, then, if,...) dans un formulaire php. voici mon fichier php si cela peut vous aider.

<!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=UTF-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.style1 {
	font-size: 18px;
	font-weight: bold;
}
-->
</style>
</head>

<body>
<p>Calcul de l'impôt personnel 2009
  <?php

if(!preg_match("#^[0-9]+$#", $_POST['a']) || !preg_match("#^[0-9]+$#", $_POST['b']) || !preg_match("#^[0-9]+$#", $_POST['c'])|| !preg_match("#^[0-9]+$#", $_POST['d'])|| !preg_match("#^[0-9]+$#", $_POST['e'])|| !preg_match("#^[0-9]+$#", $_POST['f'])|| !preg_match("#^[0-9]+$#", $_POST['g'])|| !preg_match("#^[0-9]+$#", $_POST['h'])|| !preg_match("#^[0-9]+$#", $_POST['i'])|| !preg_match("#^[0-9]+$#", $_POST['j'])|| !preg_match("#^[0-9]+$#", $_POST['k'])|| !preg_match("#^[0-9]+$#", $_POST['l'])|| !preg_match("#^[0-9]+$#", $_POST['m'])|| !preg_match("#^[0-9]+$#", $_POST['n'])|| !preg_match("#^[0-9]+$#", $_POST['o'])|| !preg_match("#^[0-9]+$#", $_POST['p'])|| !preg_match("#^[0-9]+$#", $_POST['q'])|| !preg_match("#^[0-9]+$#", $_POST['r']))
{
?>
</p>
<form method="post" action="">
  <table width="746" border="1">
    <tr>
      <td width="336"><span class="style1">Revenus</span></td>
      <td width="194">Provincial (Québec)</td>
      <td width="194">Fédéral</td>
    </tr>
    <tr>
      <td>Revenus de salaire :      </td>
      <td><input name="a" type="text" /></td>
      <td><input name="a" type="text" /></td>
    </tr>
    <tr>
      <td>Revenus de dividende (réel) :</td>
      <td><input name="c" type="text" /></td>
      <td><input name="d" type="text" /></td>
    </tr>
    <tr>
      <td>Revenus d'intérêts :</td>
      <td><input name="e" type="text" /></td>
      <td><input name="f" type="text" /></td>
    </tr>
    <tr>
      <td>Autres Revenus :</td>
      <td><label>
        <input type="text" name="g"/>
      </label></td>
      <td><input name="h" type="text" /></td>
    </tr>
    <tr>
      <td colspan="3">&nbsp;</td>
    </tr>
    <tr>
      <td colspan="3"><span class="style1">Déductions</span></td>
    </tr>
    <tr>
      <td>RRQ</td>
      <td><input type="text" name="i"/></td>
      <td bgcolor="#999999">&nbsp;</td>
    </tr>
    <tr>
      <td>REER</td>
      <td><input type="text" name="j"/></td>
      <td><input name="k" type="text" /></td>
    </tr>
    <tr>
      <td>Autres déductions</td>
      <td><input type="text" name="l"/></td>
      <td><input name="m" type="text" /></td>
    </tr>
    <tr>
      <td colspan="3">&nbsp;</td>
    </tr>
    <tr>
      <td colspan="3"><span class="style1">CRÉDITS NON REMBOURSABLES</span></td>
    </tr>
    <tr>
      <td>Montant personnel de Base</td>
      <td><div align="right">10455</div></td>
      <td><div align="right">10375</div></td>
    </tr>
    <tr>
      <td>Montant en raison de l'age (6 658$)</td>
      <td colspan="2"><label>
 Plus de 65 ans</label></td>
    </tr>
    <tr>
      <td>RRQ</td>
      <td><input type="text" name="n"/></td>
      <td bgcolor="#999999">&nbsp;</td>
    </tr>
    <tr>
      <td>Cotisation assurance emploi</td>
      <td><input type="text" name="o"/></td>
      <td><input type="text" name="p"/></td>
    </tr>
    <tr>
      <td>Autres Montants</td>
      <td><input type="text" name="q"/></td>
      <td><input type="text" name="r"/></td>
    </tr>
    <tr>
      <td colspan="3">&nbsp;</td>
    </tr>
    <tr>
      <td colspan="3"><input type="submit" value="Calculer " /></td>
    </tr>
  </table>
  <p><label></label>
  </p>
</form>
<?php
}
else
{
 $s=($_POST['a']+$_POST['c']+$_POST['e']+$_POST['g']);
 $t=($_POST['b']+$_POST['d']+$_POST['f']+$_POST['h']);
 $u=($_POST['i']+$_POST['j']+$_POST['l']);
 $v=($_POST['k']+$_POST['m']);
 $w=($_POST['s']-$_POST['u']);
 $x=($_POST['t']-$_POST['v']);
 $y=(($_POST['n']+$_POST['o']+$_POST['q']+10375)*0.15);
 $z=(($_POST['p']+$_POST['r']+10455)*0.2);
 $aa=(if $_POST['w']>76770 =$_POST['w']*0.24;
 elseif 38 385<$_POST['w']<=76770 =$_POST['w']*0.20;
 else =$_POST['w']*0.16);
 $bb=(if $_POST['w']>123264 =$_POST['w']*0.29;
 elseif 82399<$_POST['w']<=126264 =$_POST['w']*0.26;
 elseif 41200<$_POST['w']<=82399 =$_POST['w']*0.22;
 else =$_POST['w']*0.15);
 $cc=($_POST['u']*0.1);
 $dd=($_POST['v']*1.25*0.1333);
 $ee=($_POST['aa']-$_POST['y']-$_POST['cc']);
 $ff=($_POST['bb']-$_POST['z']-$_POST['dd']);
 echo 'Revenu total (Provincial) :'.$s'$';
 echo 'Revenu total (Fédéral) :'.$t'$';
 echo 'Déductions totales (Provincial) :'.$u'$';
 echo 'Déductions totales (Fédéral) :'.$v;
 echo 'Revenu imposable (Provincial) :'.$w'$';
 echo 'Revenu imposable (Fédéral) :'.$x'$';
 echo 'Crédits d\'impôts non remboursables (Provincial) :'.$y'$';
 echo 'Crédits d\'impôts non remboursables (Fédéral) :'.$z'$';
 echo 'Impôt sur le revenu imposable (Provincial) :'.$aa'$';
 echo 'Impôt sur le revenu imposable (Fédéral) :'.$bb'$';
 echo 'Crédits d\'impôts pour dividendes (Provincial) :'.$cc'$';
 echo 'Crédits d\'impôts pour dividendes (Fédéral) :'.$dd'$';
 echo '______________________________________';
 echo 'Impôts à payer (provincial) :'.$ee'$'; 
 echo 'Impôts à payer (Fédéral) :'.$ff'$';
 echo '______________________________________';
}
?>
<form id="form1" name="form1" method="post" action="">
  <input type="submit" name="button2" id="button2" value="Remise à Zéro " />
</form>
</body>
</html>


Merci à l'avance
Christophe
A voir également:

5 réponses

dodoecchi Messages postés 454 Date d'inscription samedi 9 septembre 2006 Statut Membre Dernière intervention 26 avril 2012 29
27 mai 2009 à 18:58
bah mon coco tu cherches sur internet des cours PHP chapitre conditions....
ou alors tu poses des questions plus ciblées
et au lieu de non balancer ton fichier en entier sans rien nous dire, dis nous plutot où il faut regarder......

Dorian
0
christophe.therrien Messages postés 102 Date d'inscription lundi 25 mai 2009 Statut Membre Dernière intervention 9 juin 2010 1
28 mai 2009 à 15:17
En fait mon problème c'est que mon fichier ne s'affiche pas lorsque je tente de l'ouvrir. je crois que ce sont mes restrictions (if, else) car je ne sais trop comment les intégrer dans mon fichier. de plus j'ai des restrictions à l'intérieur de d'autre restrictions (if ou else). je me demandais donc qu'elle était la bonne façon pour intégrer ces dites restrictions dans un fichier php.
0
Ozimandias Messages postés 502 Date d'inscription jeudi 14 mai 2009 Statut Membre Dernière intervention 10 mars 2010 46
28 mai 2009 à 16:28
else
{
 $s=($_POST['a']+$_POST['c']+$_POST['e']+$_POST['g']);
 $t=($_POST['b']+$_POST['d']+$_POST['f']+$_POST['h']);
 $u=($_POST['i']+$_POST['j']+$_POST['l']);
 $v=($_POST['k']+$_POST['m']);
 $w=($_POST['s']-$_POST['u']);
 $x=($_POST['t']-$_POST['v']);
 $y=(($_POST['n']+$_POST['o']+$_POST['q']+10375)*0.15);
 $z=(($_POST['p']+$_POST['r']+10455)*0.2);
 $aa=(if $_POST['w']>76770 =$_POST['w']*0.24;
 elseif 38 385<$_POST['w']<=76770 =$_POST['w']*0.20;
 else =$_POST['w']*0.16);
 $bb=(if $_POST['w']>123264 =$_POST['w']*0.29;


tu oublie la moitié des acolades et des parenthèses... je souligne 1 ou 2 exemples d'oubli...

else
{
 $s=($_POST['a']+$_POST['c']+$_POST['e']+$_POST['g']);
 $t=($_POST['b']+$_POST['d']+$_POST['f']+$_POST['h']);
 $u=($_POST['i']+$_POST['j']+$_POST['l']);
 $v=($_POST['k']+$_POST['m']);
 $w=($_POST['s']-$_POST['u']);
 $x=($_POST['t']-$_POST['v']);
 $y=(($_POST['n']+$_POST['o']+$_POST['q']+10375)*0.15);
 $z=(($_POST['p']+$_POST['r']+10455)*0.2);
 $aa=( if  (  $_POST['w']>76770 =$_POST['w']*0.24;
 elseif 38 385<$_POST['w']<=76770 =$_POST['w']*0.20;
 else {  =$_POST['w']*0.16);
 $bb=(if $_POST['w']>123264 =$_POST['w']*0.29;
0
christophe.therrien Messages postés 102 Date d'inscription lundi 25 mai 2009 Statut Membre Dernière intervention 9 juin 2010 1
28 mai 2009 à 16:32
d'accord je vais regarder

merci
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
christophe.therrien Messages postés 102 Date d'inscription lundi 25 mai 2009 Statut Membre Dernière intervention 9 juin 2010 1
28 mai 2009 à 16:36
je crois que là c'est mieux, j'ai tout réorganiser...mais je suis pas sûr où j'ai besoin de parenthèses et d'accolade!

if($_POST['w']>76770)
 {
 $aa=($_POST['w']*0.24);
 echo 'Impôt sur le revenu imposable (Provincial) :'.$aa'$';
 }
 elseif(38 385<$_POST['w']<=76770)
 {
 $aa=($_POST['w']*0.20);
 echo 'Impôt sur le revenu imposable (Provincial) :'.$aa'$';
 }
 else 
 {
 $aa=($_POST['w']*0.16);
 echo 'Impôt sur le revenu imposable (Provincial) :'.$aa'$';
 }
 if($_POST['w']>123264)
 {
 $bb=$_POST['w']*0.29;
 echo 'Impôt sur le revenu imposable (Fédéral) :'.$bb'$';
 }
 elseif(82399<$_POST['w']<=126264)
 {
 $bb=$_POST(['w']*0.26);
 echo 'Impôt sur le revenu imposable (Fédéral) :'.$bb'$';
 }
 elseif(41200<$_POST['w']<=82399)
 {
 $bb=($_POST['w']*0.22);
 echo 'Impôt sur le revenu imposable (Fédéral) :'.$bb'$';
 }
 else 
 {
 $bb=($_POST['w']*0.15);
 echo 'Impôt sur le revenu imposable (Fédéral) :'.$bb'$';
 }
 $cc=($_POST['u']*0.1);
 echo 'Crédits d\'impôts pour dividendes (Provincial) :'.$cc'$';
 $dd=($_POST['v']*1.25*0.1333);
 echo 'Crédits d\'impôts pour dividendes (Fédéral) :'.$dd'$';
 $ee=($_POST['aa']-$_POST['y']-$_POST['cc']);
  echo '______________________________________';
  echo 'Impôts à payer (provincial) :'.$ee'$';
 $ff=($_POST['bb']-$_POST['z']-$_POST['dd']);
  echo 'Impôts à payer (Fédéral) :'.$ff'$';
  echo '______________________________________';
}
0