MezData-Logo 596 Creative Commons License Lösungen Button :WEBPUBLISH: Übungen zu Formularen

Turnschuhhändler

Die Bestellung wird mit der GET-Methode an bestellung.php übermittelt. Die Namen der Felder lauten:

windhund, wgroesse, schleichkatze, sgroesse, agb

Auswählbare Schuhgrössen sind 38,39,40.41.42.43

Erstellen Sie den HTML-Quellcode für das Formular.

Quellcode [Quellcode]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

  <head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
    <title>Turnschuhhändler</title>
        <style type="text/css" media="screen"><!--
body { font-family: Helvetica, Geneva, Arial, SunSans-Regular, sans-serif; background-color: #ffef44; }
--></style>
    </head>

  <body>
    <h2>Turnschuhhandlung</h2>
    <form action="bestellung.php" method="get">
      <table border="1" cellspacing="0" cellpadding="4">
        <tr>
          <th>Anzahl</th>
          <th>Artikel</th>
          <th>Preis</th>
          <th>Grösse</th>
        </tr>
        <tr>
          <td><input type="text" name="windhund" value="0" size="4"></td>
          <td>Windhund</td>
          <td>150€</td>
          <td><select name="wgroesse" size="1">
              <option selected value="0">auswählen</option>
              <option value="38">38</option>
              <option value="39">38</option>
              <option value="40">40</option>
              <option value="41">41</option>
              <option value="42">42</option>
              <option value="43">43</option>
            </select></td>
        </tr>
        <tr>
          <td><input type="text" name="schleichkatze" value="0" size="4"></td>
          <td>Schleichkatze</td>
          <td>200€</td>
          <td><select name="sgroesse" size="1">
              <option selected value="0">auswählen</option>
              <option value="38">38</option>
              <option value="39">38</option>
              <option value="40">40</option>
              <option value="41">41</option>
              <option value="42">42</option>
              <option value="43">43</option>
            </select></td>
        </tr>
        <tr>
          <td colspan="3"><input type="checkbox" name="agb" value="true"> Ich bin mit der AGB einverstanden.</td>
          <td><input type="submit" name="" value="Bestellen"></td>
        </tr>
      </table>
    </form>
  </body>

</html>

Auswertung der Eingaben.

Erstellen Sie PHP-Code oder ein Struktogramm für ein Unterprogramm bestellung(windhund, wgroesse,schleichkatze, sgroesse:GZ, agb:Bool) .

Quellcode [Quellcode]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

    <head>
        <meta http-equiv="content-type" content="text/html;charset=utf-8">
        <title>Bestellung</title>
        <style type="text/css" media="screen"><!--
body { font-family: Helvetica, Geneva, Arial, SunSans-Regular, sans-serif; background-color: #ff3; }
--></style>
    </head>
    <body>
        <h2>Vielen Dank für Ihren Auftrag</h2>
        <p><?php
          
if (isset($_GET['windhund']) && $_GET['wgroesse'] && isset($_GET['schleichkatze']) && $_GET['sgroesse'])
            
bestellung($_GET['windhund'],$_GET['wgroesse'],$_GET['schleichkatze'],$_GET['sgroesse'],$_GET['agb']);
          else
              echo 
'Keine gültige Anfrage!';
        
          function 
bestellung($windhund$wgroesse$schleichkatze$sgroesse$agb){
            
$ok true;
            if (
$windhund==&& $schleichkatze == 0)
              echo 
'Sie haben nichts bestellt.';
            else if (
$agb!='true')
              echo 
'Sie haben der AGB nicht zu gestimmt.';
            else{
              if (
$windhund>&& $wgroesse <=0){
                echo 
'Bitte Schuhgrösse für Windhund auswählen';
                
$ok=false;
              }
              if (
$schleichkatze>&& $sgroesse <=0){
                echo 
'Bitte Schuhgrösse für Schleichkatze auswählen';
                
$ok=false;
              }
              if (
$ok){
                if (
$windhund>0){
                  echo 
'Sie haben '.$windhund.' Windhund Grösse '.$wgroesse.' bestellt.<br>';
                  
$summe $windhund*150;
                }
                if (
$schleichkatze>0){
                  echo 
'Sie haben '.$schleichkatze.' Schleichkatze Grösse '.$sgroesse.' bestellt.<br>';
                  
$summe += $schleichkatze*200;
                }
                echo 
'<br>Die Bestellsumme beträgt: '.$summe.' Euro.';
              }
            }
          }
        
?></p>
    </body>
</html>

© Oliver Mezger 18.03.2010 MezData.de Den Kontakt herstellen...