Regex bouton Radio [PHP]

Fermé
christophe.therrien Messages postés 102 Date d'inscription lundi 25 mai 2009 Statut Membre Dernière intervention 9 juin 2010 - 19 juin 2009 à 16:36
christophe.therrien Messages postés 102 Date d'inscription lundi 25 mai 2009 Statut Membre Dernière intervention 9 juin 2010 - 19 juin 2009 à 20:16
Bonjour, j'aimerais savoir comment faire une regex pour un bouton radio car je crois que c'Est ce qui empêche mon formulaire de fonctionner correctement.

Merci à vous tous "beast du PHP"!
Christophe
A voir également:

15 réponses

gigaga Messages postés 2346 Date d'inscription vendredi 20 juin 2008 Statut Membre Dernière intervention 22 août 2014 301
19 juin 2009 à 16:37
Tu peux etre un peu plus précis... Quel est le rapport entre une expression régulière et un bouton radio? Que veux tu faire?
0
christophe.therrien Messages postés 102 Date d'inscription lundi 25 mai 2009 Statut Membre Dernière intervention 9 juin 2010 1
19 juin 2009 à 16:41
En fait c'est que j'ai un formulaire ou l'utilisateurs doit entrer plusieurs variables et je lui demande si oui ou non son entreprise est sous contrôle canadiens. Va voir ma page, tu comprendras j'en suis sur. http://www.tlcomptables.com/calcul7.php

En ce moment j'ai un preg_match sur tous mes champs de textes

Merci
Christophe
0
Alain_42 Messages postés 5361 Date d'inscription dimanche 3 février 2008 Statut Membre Dernière intervention 13 février 2017 894
19 juin 2009 à 17:32
Déja une anomalie:

ton bouton Remise à Zéro ne doit pas être dans un autre formulaire, tel que tu fais ça poste un formulaire inexistant il faut mettre ce bouton dans le premier formulaire et avec le type="reset"

et pour tester ton bouton radio il suffir de lire sa valeur postée $_POST['xx']
0
christophe.therrien Messages postés 102 Date d'inscription lundi 25 mai 2009 Statut Membre Dernière intervention 9 juin 2010 1
19 juin 2009 à 17:44
Le bouton reset c'est parce que lorsque j'envoie le formulaire, il disparait et je ne peux donc pas faire un reset. Tu ne connaitrais pas par le fait même un moyen de garder le formulaire après l'avoir envoyé.
0

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

Posez votre question
Alain_42 Messages postés 5361 Date d'inscription dimanche 3 février 2008 Statut Membre Dernière intervention 13 février 2017 894
19 juin 2009 à 18:07
Voilà une solution:

<!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>Calcul des cr&eacute;dits d'imp&ocirc;ts à la R&amp;D pour une entreprise au Qu&eacute;bec</title>
</head>

<body>
<?php
if(isset($_POST['calculer'])){
	//le bouton calculer a ete cliqué  ///attention il faut un name à tous les input même aux boutons !
if(isset($_POST['a'])){$a=$_POST['a'];}else{$a=0;}
//tu fais pareil pour tous les champs

}

?>
<p>Calcul des crédits d'impôts à la R&amp;D pour une entreprise au Québec
  
  </p>
<form method="post" action="">
  <table width="810" border="1">
    <tr>

      <td width="400">Revenu imposable de l'ann&eacute;e pr&eacute;c&eacute;dente</td>
		<!-- et la tu mets value=".... -->
      <td colspan="2"> <input name="a" type="text" value="<?php echo $a; ?>" /></td>
    </tr>
    <tr>
      <td><label></label>
        Soci&eacute;t&eacute; priv&eacute;e sous contrôle canadien</td>
      <td colspan="2"><p>

        <label></label>
        <label>
        <input name="xx" type="radio" value="oui" checked="checked"  />
oui</label>
        <input type="radio" name="xx" value="non"  />
        <label>non</label>
<br />
        <label></label>
        <label></label>

        </p>        
      <label></label></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td width="194">Qu&eacute;bec</td>
      <td width="194">Canada(hors Québec)</td>
    </tr>

    <tr>
      <td>Salaires directement reli&eacute;s à la R&amp;D</td>
      <td><input name="b" type="text" id="b" value="0" /></td>
      <td><input name="c" type="text" id="c" value="0" /></td>
    </tr>
    <tr>
      <td>Salaires indirectement reli&eacute;s à la R&amp;D</td>

      <td><input name="d" type="text" id="d" value="0" /></td>
      <td><input name="e" type="text" id="e" value="0" /></td>
    </tr>
    <tr>
      <td>Sous-traitants non li&eacute; &agrave; l'entreprise</td>
      <td><input name="f" type="text" id="f" value="0" /></td>
      <td><input name="g" type="text" id="g" value="0" /></td>
    </tr>

    <tr>
      <td><p>Fournitures utilis&eacute;es directement en R&amp;D</p>      </td>
      <td><input name="g" type="text" id="g" value="0" /></td>
      <td><input name="i" type="text" id="i" value="0" /></td>
    </tr>
    <tr>
      <td colspan="3"><strong>D&eacute;penses en Capital</strong></td>

    </tr>
    <tr>
      <td><p>Utilisation 100% en R&amp;D</p>      </td>
      <td><input name="j" type="text" id="j" value="0" /></td>
      <td><input name="k" type="text" id="k" value="0" /></td>
    </tr>
    <tr>

      <td colspan="3"><input type="submit" name="calculer" value="Calculer " /></td>
    </tr>
  </table>
  <p><label></label>
  </p>


  <input type="reset" name="button2" id="button2" value="Remise à Zéro " />
</form>
</body>

</html>
0
christophe.therrien Messages postés 102 Date d'inscription lundi 25 mai 2009 Statut Membre Dernière intervention 9 juin 2010 1
19 juin 2009 à 18:23
Merci alain_42, je comprends ce que tu veux faire mais je ne vois pas ce qui ne marche pas dans ma page car j'utilise le même modèle pour d'autres page et celles-ci marchent parfaitement, la seule chose c'est qu'elles nont pas de bouton radio. Pourquoi? mais sinon merci pour cette solution

Christophe
0
christophe.therrien Messages postés 102 Date d'inscription lundi 25 mai 2009 Statut Membre Dernière intervention 9 juin 2010 1
19 juin 2009 à 18:24
Peut être qu'avec le code tu comprendras mieux
<!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>Calcul des crédits d'impôts à la R&amp;D pour une entreprise au Québec</title>
</head>

<body>
<p>Calculdes crédits d'impôts à la R&amp;D pour une entreprise au Québec
  
  <?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']))
{
?>
</p>
<form method="post" action="">
  <table width="810" border="1">
    <tr>
      <td width="400">Revenu imposable de l'année précédente</td>
      <td colspan="2"> <input name="a" type="text" value="<?=$_POST["a"]?>0" /></td>
    </tr>
    <tr>
      <td><label></label>
        Société privée sous contrôle canadien</td>
      <td colspan="2"><p>
        <label></label>
        <label>
        <input name="xx" type="radio" value="oui" checked="checked"  />
oui</label>
        <input type="radio" name="xx" value="non"  />
        <label>non</label>
<br />
        <label></label>
        <label></label>
        </p>        
      <label></label></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td width="194">Québec</td>
      <td width="194">Canada(hors Québec)</td>
    </tr>
    <tr>
      <td>Salaires directement reliés à la R&amp;D</td>
      <td><input name="b" type="text" id="b" value="<?=$_POST["b"]?>0" /></td>
      <td><input name="c" type="text" id="c" value="<?=$_POST["c"]?>0" /></td>
    </tr>
    <tr>
      <td>Salaires indirectement reliés à la R&amp;D</td>
      <td><input name="d" type="text" id="d" value="<?=$_POST["d"]?>0" /></td>
      <td><input name="e" type="text" id="e" value="<?=$_POST["e"]?>0" /></td>
    </tr>
    <tr>
      <td>Sous-traitants non lié à l'entreprise</td>
      <td><input name="f" type="text" id="f" value="<?=$_POST["f"]?>0" /></td>
      <td><input name="g" type="text" id="g" value="<?=$_POST["g"]?>0" /></td>
    </tr>
    <tr>
      <td><p>Fournitures utilisées directement en R&amp;D</p>      </td>
      <td><input name="g" type="text" id="g" value="<?=$_POST["g"]?>0" /></td>
      <td><input name="i" type="text" id="i" value="<?=$_POST["i"]?>0" /></td>
    </tr>
    <tr>
      <td colspan="3"><strong>Dépenses en Capital</strong></td>
    </tr>
    <tr>
      <td><p>Utilisation 100% en R&amp;D</p>      </td>
      <td><input name="j" type="text" id="j" value="<?=$_POST["j"]?>0" /></td>
      <td><input name="k" type="text" id="k" value="<?=$_POST["k"]?>0" /></td>
    </tr>
    <tr>
      <td colspan="3"><input type="submit" value="Calculer " /></td>
    </tr>
  </table>
  <p><label></label>
  </p>

<?php
}
else
{
 $n=($_POST['b']+$_POST['d']+($_POST['f']/2));
 echo 'Dépenses totales (Québec) :'.$n.'$';
 if($_POST['xx']=="oui") 
 {
  if($n>3000000)
  {
  $o=((3000000*0.375)+(($n-3000000)*0.1775));
  echo 'Crédits RD (Québec) :'.$o.'$';
  }
  else
  {
  $o=($n*0.375);
  echo 'Crédits RD (Québec) :'.$o.'$';
  }
 
 $p=($_POST['b']+$_POST['c']+$_POST['d']+$_POST['e']+$_POST['f']+$_POST['g']+$_POST['h']+$_POST['i']-($o));
 echo 'Dépenses totales (Canada) :'.$p.'$';
  if($p>=3000000)
  {
   if($_POST['a']>=400000)
   {
   $q=(((3000000-(($_POST['a']-400000)*10))*0.35)+(($p-(3000000-(($_POST['a']-400000)*10)))*0.2));
   echo 'Crédits RD (Canada) :'.$q.'$';
   }
   else 
   {
   $q=((3000000*0.35)+(($p-3000000)*0.2));
   echo 'Crédits RD (Canada) :'.$q.'$';
   }
  } 
  else
  {
   if($_POST['a']>400000)
   {
    if($p>(300000-(($_POST['a']-400000)*10)))  
	{
   	$q=(($p-(300000-(($_POST['a']-400000)*10))*0.2)+(300000-((($_POST['a']-400000)*10)*0.35)));
    echo 'Crédits RD (Canada) :'.$q.'$';
	}
    else
	{
	$q=($p*0.35);
	echo 'Crédits RD (Canada) :'.$q.'$';
	}	
   }
   else
   {
   $q=($p*0.35);
   echo 'Crédits RD (Canada) :'.$q.'$';
   }
  }
 } 
 else
 {
 $o=($n*0.1775);
 echo 'Crédits RD (Québec) :'.$o.'$';
 $q=($p*0.2);
 echo 'Crédits RD (Canada) :'.$q.'$';
 } 
}
?>
</form>
<form action="" method="post" name="form1" id="form1">
  <input type="submit" name="button2" id="button2" value="Remise à Zéro " />
</form>
</body>
</html>
0
Alain_42 Messages postés 5361 Date d'inscription dimanche 3 février 2008 Statut Membre Dernière intervention 13 février 2017 894
19 juin 2009 à 18:28
Ce que je veux faire en réponse à ta précédente question c'est mettre la value d'un champ déjà saisi lorsque ta page se recharge

pour cela au début tu as la partie php qui récupère la value postée ou mets zero sinon

et cette variable ajoutée dans l'<INPUT ...... value="<?php echo ....

sinon qu'est ce qui ne marche pas ?
0
christophe.therrien Messages postés 102 Date d'inscription lundi 25 mai 2009 Statut Membre Dernière intervention 9 juin 2010 1
19 juin 2009 à 18:30
Mon formulaire n'affiche pas les réponses, si tu vas sur la page http://tlcomptables.com/calcul7.php il ne fait qu'ajouter des 0 à ce qu'on a entré

christophe
0
Alain_42 Messages postés 5361 Date d'inscription dimanche 3 février 2008 Statut Membre Dernière intervention 13 février 2017 894
19 juin 2009 à 18:37
je ne vois pas la partie php alors donnes moi ton code complet
0
christophe.therrien Messages postés 102 Date d'inscription lundi 25 mai 2009 Statut Membre Dernière intervention 9 juin 2010 1
19 juin 2009 à 18:40
il est un peu plus haut...

le re voici
<!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>Calcul des crédits d'impôts à la R&amp;D pour une entreprise au Québec</title>
</head>

<body>
<p>Calculdes crédits d'impôts à la R&amp;D pour une entreprise au Québec
  
  <?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']))
{
?>
</p>
<form method="post" action="">
  <table width="810" border="1">
    <tr>
      <td width="400">Revenu imposable de l'année précédente</td>
      <td colspan="2"> <input name="a" type="text" value="<?=$_POST["a"]?>0" /></td>
    </tr>
    <tr>
      <td><label></label>
        Société privée sous contrôle canadien</td>
      <td colspan="2"><p>
        <label></label>
        <label>
        <input name="xx" type="radio" value="oui" checked="checked"  />
oui</label>
        <input type="radio" name="xx" value="non"  />
        <label>non</label>
<br />
        <label></label>
        <label></label>
        </p>        
      <label></label></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td width="194">Québec</td>
      <td width="194">Canada(hors Québec)</td>
    </tr>
    <tr>
      <td>Salaires directement reliés à la R&amp;D</td>
      <td><input name="b" type="text" id="b" value="<?=$_POST["b"]?>0" /></td>
      <td><input name="c" type="text" id="c" value="<?=$_POST["c"]?>0" /></td>
    </tr>
    <tr>
      <td>Salaires indirectement reliés à la R&amp;D</td>
      <td><input name="d" type="text" id="d" value="<?=$_POST["d"]?>0" /></td>
      <td><input name="e" type="text" id="e" value="<?=$_POST["e"]?>0" /></td>
    </tr>
    <tr>
      <td>Sous-traitants non lié à l'entreprise</td>
      <td><input name="f" type="text" id="f" value="<?=$_POST["f"]?>0" /></td>
      <td><input name="g" type="text" id="g" value="<?=$_POST["g"]?>0" /></td>
    </tr>
    <tr>
      <td><p>Fournitures utilisées directement en R&amp;D</p>      </td>
      <td><input name="g" type="text" id="g" value="<?=$_POST["g"]?>0" /></td>
      <td><input name="i" type="text" id="i" value="<?=$_POST["i"]?>0" /></td>
    </tr>
    <tr>
      <td colspan="3"><strong>Dépenses en Capital</strong></td>
    </tr>
    <tr>
      <td><p>Utilisation 100% en R&amp;D</p>      </td>
      <td><input name="j" type="text" id="j" value="<?=$_POST["j"]?>0" /></td>
      <td><input name="k" type="text" id="k" value="<?=$_POST["k"]?>0" /></td>
    </tr>
    <tr>
      <td colspan="3"><input type="submit" value="Calculer " /></td>
    </tr>
  </table>
  <p><label></label>
  </p>

<?php
}
else
{
 $n=($_POST['b']+$_POST['d']+($_POST['f']/2));
 echo 'Dépenses totales (Québec) :'.$n.'$';
 if($_POST['xx']=="oui") 
 {
  if($n>3000000)
  {
  $o=((3000000*0.375)+(($n-3000000)*0.1775));
  echo 'Crédits RD (Québec) :'.$o.'$';
  }
  else
  {
  $o=($n*0.375);
  echo 'Crédits RD (Québec) :'.$o.'$';
  }
 
 $p=($_POST['b']+$_POST['c']+$_POST['d']+$_POST['e']+$_POST['f']+$_POST['g']+$_POST['h']+$_POST['i']-($o));
 echo 'Dépenses totales (Canada) :'.$p.'$';
  if($p>=3000000)
  {
   if($_POST['a']>=400000)
   {
   $q=(((3000000-(($_POST['a']-400000)*10))*0.35)+(($p-(3000000-(($_POST['a']-400000)*10)))*0.2));
   echo 'Crédits RD (Canada) :'.$q.'$';
   }
   else 
   {
   $q=((3000000*0.35)+(($p-3000000)*0.2));
   echo 'Crédits RD (Canada) :'.$q.'$';
   }
  } 
  else
  {
   if($_POST['a']>400000)
   {
    if($p>(300000-(($_POST['a']-400000)*10)))  
	{
   	$q=(($p-(300000-(($_POST['a']-400000)*10))*0.2)+(300000-((($_POST['a']-400000)*10)*0.35)));
    echo 'Crédits RD (Canada) :'.$q.'$';
	}
    else
	{
	$q=($p*0.35);
	echo 'Crédits RD (Canada) :'.$q.'$';
	}	
   }
   else
   {
   $q=($p*0.35);
   echo 'Crédits RD (Canada) :'.$q.'$';
   }
  }
 } 
 else
 {
 $o=($n*0.1775);
 echo 'Crédits RD (Québec) :'.$o.'$';
 $q=($p*0.2);
 echo 'Crédits RD (Canada) :'.$q.'$';
 } 
}
?>
</form>
<form action="" method="post" name="form1" id="form1">
  <input type="submit" name="button2" id="button2" value="Remise à Zéro " />
</form>
</body>
</html>
0
Alain_42 Messages postés 5361 Date d'inscription dimanche 3 février 2008 Statut Membre Dernière intervention 13 février 2017 894
19 juin 2009 à 18:51
c'est normal tu avais laissé le 0 après value="<?php echo $_POST['a']0" !

<!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>Calcul des crédits d'impôts à la R&amp;D pour une entreprise au Québec</title>
</head>

<body>
<p>Calculdes crédits d'impôts à la R&amp;D pour une entreprise au Québec
  
  <?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']))
{

?>
</p>
<form method="post" action="">
  <table width="810" border="1">
    <tr>
      <td width="400">Revenu imposable de l'année précédente</td>
      <td colspan="2"> <input name="a" type="text" value="<?=$_POST["a"]?>" /></td>
    </tr>
    <tr>
      <td><label></label>
        Société privée sous contrôle canadien</td>
      <td colspan="2"><p>
        <label></label>
        <label>
        <input name="xx" type="radio" value="oui" checked="checked"  />
oui</label>
        <input type="radio" name="xx" value="non"  />
        <label>non</label>
<br />
        <label></label>
        <label></label>
        </p>        
      <label></label></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td width="194">Québec</td>
      <td width="194">Canada(hors Québec)</td>
    </tr>
    <tr>
      <td>Salaires directement reliés à la R&amp;D</td>
      <td><input name="b" type="text" id="b" value="<?=$_POST["b"]?>" /></td>
      <td><input name="c" type="text" id="c" value="<?=$_POST["c"]?>" /></td>
    </tr>
    <tr>
      <td>Salaires indirectement reliés à la R&amp;D</td>
      <td><input name="d" type="text" id="d" value="<?=$_POST["d"]?>" /></td>
      <td><input name="e" type="text" id="e" value="<?=$_POST["e"]?>" /></td>
    </tr>
    <tr>
      <td>Sous-traitants non lié à l'entreprise</td>
      <td><input name="f" type="text" id="f" value="<?=$_POST["f"]?>" /></td>
      <td><input name="g" type="text" id="g" value="<?=$_POST["g"]?>" /></td>
    </tr>
    <tr>
      <td><p>Fournitures utilisées directement en R&amp;D</p>      </td>
      <td><input name="g" type="text" id="g" value="<?=$_POST["g"]?>" /></td>
      <td><input name="i" type="text" id="i" value="<?=$_POST["i"]?>" /></td>
    </tr>
    <tr>
      <td colspan="3"><strong>Dépenses en Capital</strong></td>
    </tr>
    <tr>
      <td><p>Utilisation 100% en R&amp;D</p>      </td>
      <td><input name="j" type="text" id="j" value="<?=$_POST["j"]?>" /></td>
      <td><input name="k" type="text" id="k" value="<?=$_POST["k"]?>" /></td>
    </tr>
    <tr>
      <td colspan="3"><input type="submit" value="Calculer " /></td>
    </tr>
  </table>
  <p><label></label>
  </p>

<?php
}
else
{
 $n=($_POST['b']+$_POST['d']+($_POST['f']/2));
 echo 'Dépenses totales (Québec) :'.$n.'$';
 if($_POST['xx']=="oui") 
 {
  if($n>3000000)
  {
  $o=((3000000*0.375)+(($n-3000000)*0.1775));
  echo 'Crédits RD (Québec) :'.$o.'$';
  }
  else
  {
  $o=($n*0.375);
  echo 'Crédits RD (Québec) :'.$o.'$';
  }
 
 $p=($_POST['b']+$_POST['c']+$_POST['d']+$_POST['e']+$_POST['f']+$_POST['g']+$_POST['h']+$_POST['i']-($o));
 echo 'Dépenses totales (Canada) :'.$p.'$';
  if($p>=3000000)
  {
   if($_POST['a']>=400000)
   {
   $q=(((3000000-(($_POST['a']-400000)*10))*0.35)+(($p-(3000000-(($_POST['a']-400000)*10)))*0.2));
   echo 'Crédits RD (Canada) :'.$q.'$';
   }
   else 
   {
   $q=((3000000*0.35)+(($p-3000000)*0.2));
   echo 'Crédits RD (Canada) :'.$q.'$';
   }
  } 
  else
  {
   if($_POST['a']>400000)
   {
    if($p>(300000-(($_POST['a']-400000)*10)))  
	{
   	$q=(($p-(300000-(($_POST['a']-400000)*10))*0.2)+(300000-((($_POST['a']-400000)*10)*0.35)));
    echo 'Crédits RD (Canada) :'.$q.'$';
	}
    else
	{
	$q=($p*0.35);
	echo 'Crédits RD (Canada) :'.$q.'$';
	}	
   }
   else
   {
   $q=($p*0.35);
   echo 'Crédits RD (Canada) :'.$q.'$';
   }
  }
 } 
 else
 {
 $o=($n*0.1775);
 echo 'Crédits RD (Québec) :'.$o.'$';
 $q=($p*0.2);
 echo 'Crédits RD (Canada) :'.$q.'$';
 } 
}
?>
</form>
<form action="" method="post" name="form1" id="form1">
  <input type="submit" name="button2" id="button2" value="Remise à Zéro " />
</form>
</body>
</html>
0
christophe.therrien Messages postés 102 Date d'inscription lundi 25 mai 2009 Statut Membre Dernière intervention 9 juin 2010 1
19 juin 2009 à 18:59
d'accord, maintenant il n'affiche plus les 0 mais il n'affiche pas les réponses non plus!
0
Alain_42 Messages postés 5361 Date d'inscription dimanche 3 février 2008 Statut Membre Dernière intervention 13 février 2017 894
19 juin 2009 à 20:09
maintenat je t'ai fait ps mal de modifs ça marche

j'ai rectifié une erreur i y a avait deux fois name="g" et déplacé le bouton "reset"

et il ne faiut pas mettre zero par défaut sinon pb pour tester avec preg_match

j'ai aussi rajouté des <br /> pour affichage des résultats:

<!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>Calcul des cr&eacute;dits d'imp&ocirc;ts &agrave; la R&amp;D pour une entreprise au Qu&eacute;bec</title>
</head>

<body>
<p>Calcul des cr&eacute;dits d'imp&ocirc;ts &agrave; la R&amp;D pour une entreprise au Qu&eacute;bec
  
  <?php
//methode ternaire on teste si la variable est postee si oui elle prend la valeur de $_POST sinon elle est forcee à vide
// si tu mets par defaut les valeurs a zero comment veux tu tester ensuite avec preg_match par rapport à [0-9]
$a=isset($_POST['a'])? $_POST['a'] : "";
$b=isset($_POST['b'])? $_POST['b'] : "";
$c=isset($_POST['c'])? $_POST['c'] : "";
$d=isset($_POST['d'])? $_POST['d'] : "";
$e=isset($_POST['e'])? $_POST['e'] : "";
$f=isset($_POST['f'])? $_POST['f'] : "";
$g=isset($_POST['g'])? $_POST['g'] : "";
$h=isset($_POST['h'])? $_POST['h'] : "";
$i=isset($_POST['i'])? $_POST['i'] : "";
$j=isset($_POST['j'])? $_POST['j'] : "";
$k=isset($_POST['k'])? $_POST['k'] : "";


if(!preg_match("#^[0-9]+$#",$a) || !preg_match("#^[0-9]+$#", $b) || !preg_match("#^[0-9]+$#", $c) || !preg_match("#^[0-9]+$#", $d) || !preg_match("#^[0-9]+$#", $e) 
|| !preg_match("#^[0-9]+$#", $f) || !preg_match("#^[0-9]+$#", $g) || !preg_match("#^[0-9]+$#", $h) || !preg_match("#^[0-9]+$#", $i) || !preg_match("#^[0-9]+$#", $j)
 || !preg_match("#^[0-9]+$#", $k))
{

?>
</p>
<form method="post" action="">
  <table width="810" border="1">
    <tr>
      <td width="400">Revenu imposable de l'ann&eacute;e pr&eacute;c&eacute;dente</td>
      <td colspan="2"> <input name="a" type="text" value="<?php echo $a; ?>" /></td>
    </tr>
    <tr>
      <td><label></label>
        Soci&eacute;t&eacute; priv&eacute;e sous contr&ocirc;le canadien</td>
      <td colspan="2"><p>
        <label></label>
        <label>
        <input name="xx" type="radio" value="oui" checked="checked"  />
oui</label>
        <input type="radio" name="xx" value="non"  />
        <label>non</label>
<br />
        <label></label>
        <label></label>
        </p>        
      <label></label></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td width="194">Qu&eacute;bec</td>
      <td width="194">Canada(hors Qu&eacute;bec)</td>
    </tr>
    <tr>
      <td>Salaires directement reli&eacute;s &agrave; la R&amp;D</td>
      <td><input name="b" type="text" id="b" value="<?php echo $b; ?>" /></td>
      <td><input name="c" type="text" id="c" value="<?php echo $c; ?>" /></td>
    </tr>
    <tr>
      <td>Salaires indirectement reli&eacute;s &agrave; la R&amp;D</td>
      <td><input name="d" type="text" id="d" value="<?php echo $d; ?>" /></td>
      <td><input name="e" type="text" id="e" value="<?php echo $e; ?>" /></td>
    </tr>
    <tr>
      <td>Sous-traitants non li&eacute;s &agrave; l'entreprise</td>
      <td><input name="f" type="text" id="f" value="<?php echo $f; ?>" /></td>
      <td><input name="g" type="text" id="g" value="<?php echo $g; ?>" /></td>
    </tr>
    <tr>
      <td><p>Fournitures utilis&eacute;es directement en R&amp;D</p>      </td>
      <td><input name="h" type="text" id="h" value="<?php echo $h; ?>" /></td>
      <td><input name="i" type="text" id="i" value="<?php echo $i; ?>" /></td>
    </tr>
    <tr>
      <td colspan="3"><strong>D&eacute;penses en Capital</strong></td>
    </tr>
    <tr>
      <td><p>Utilisation 100% en R&amp;D</p>      </td>
      <td><input name="j" type="text" id="j" value="<?php echo $j; ?>" /></td>
      <td><input name="k" type="text" id="k" value="<?php echo $k; ?>" /></td>
    </tr>
    <tr>
      <td colspan="3"><input type="submit" name="calculer" value="Calculer " /></td>
    </tr>
  </table>
  <p>
  <input type="reset" name="button2" id="button2" value="Remise &agrave; Z&eacute;ro " />
  <label></label>
  </p>

<?php
}
else
{
 $n=($_POST['b']+$_POST['d']+($_POST['f']/2));
 echo 'D&eacute;penses totales (Qu&eacute;bec) :'.$n.'$<br />';
 if($_POST['xx']=="oui") 
 {
  if($n>3000000)
  {
  $o=((3000000*0.375)+(($n-3000000)*0.1775));
  echo 'Cr&eacute;dits RD (Qu&eacute;bec) :'.$o.'$<br />';
  }
  else
  {
  $o=($n*0.375);
  echo 'Cr&eacute;dits RD (Qu&eacute;bec) :'.$o.'$<br />';
  }
 
 $p=($_POST['b']+$_POST['c']+$_POST['d']+$_POST['e']+$_POST['f']+$_POST['g']+$_POST['h']+$_POST['i']-($o));
 echo 'D&eacute;penses totales (Canada) :'.$p.'$<br />';
  if($p>=3000000)
  {
   if($_POST['a']>=400000)
   {
   $q=(((3000000-(($_POST['a']-400000)*10))*0.35)+(($p-(3000000-(($_POST['a']-400000)*10)))*0.2));
   echo 'Cr&eacute;dits RD (Canada) :'.$q.'$<br />';
   }
   else 
   {
   $q=((3000000*0.35)+(($p-3000000)*0.2));
   echo 'Cr&eacute;dits RD (Canada) :'.$q.'$<br />';
   }
  } 
  else
  {
   if($_POST['a']>400000)
   {
    if($p>(300000-(($_POST['a']-400000)*10)))  
	{
   	$q=(($p-(300000-(($_POST['a']-400000)*10))*0.2)+(300000-((($_POST['a']-400000)*10)*0.35)));
    echo 'Cr&eacute;dits RD (Canada) :'.$q.'$<br />';
	}
    else
	{
	$q=($p*0.35);
	echo 'Cr&eacute;dits RD (Canada) :'.$q.'$<br />';
	}	
   }
   else
   {
   $q=($p*0.35);
   echo 'Cr&eacute;dits RD (Canada) :'.$q.'$<br />';
   }
  }
 } 
 else
 {
 $o=($n*0.1775);
 echo 'Cr&eacute;dits RD (Québec) :'.$o.'$<br />';
 $q=($p*0.2);
 echo 'Cr&eacute;dits RD (Canada) :'.$q.'$<br />';
 } 
}
?>
</form>

</body>
</html>
0
christophe.therrien Messages postés 102 Date d'inscription lundi 25 mai 2009 Statut Membre Dernière intervention 9 juin 2010 1
19 juin 2009 à 20:16
EXCELENTÉ! Sincèrement merci beaucoup alain_42

Christophe (un gars très heureux)
0