Webbserverprogrammering 1

Show sourcecode

The following files exists in this folder. Click to view.

webbsrvprg/exercises/form/egetformular/

egetfomrular3.php
egetformular5.php

egetformular5.php

136 lines UTF-8 Windows (CRLF)
<?php
error_reporting
(-1); // Report all type of errors
ini_set('display_errors'1); // Display all errors 
ini_set('output_buffering'0); // Do not buffer outputs, write directly
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Eget formulär</title>
</head>

<body>
    <form method="post" action="">
        <?php if(count($_POST) == 0) { ?>
            <label for="name">Namn</label><br>
            <input type="text" name="name"> <br>
            <label for="epost">Email</label><br>
            <input type="email" name="epost"> <br>
            <label for="pw">Lösenord</label><br>
            <input type="password" name="pw"> <br>
            <input type="submit" value="Skicka">
        <?php } if(count($_POST) == 3) {
                if(
$_POST["pw"] != "CARTI"){
                    echo 
"Fel lösenord! <br>";
                    echo 
"<input type=\"submit\" value=\"Gå tillbaka\">";
                }
                else {
?>
        <div>
            Vem är bästa musik artisten?
            <div>
                <input type="radio" name="fraga1" value="Carti" id="">
                <label for="Carti">Jordan Carter</label>
            </div>
            <div>
                <input type="radio" name="fraga1" value="ye" id="">
                <label for="ye">ye</label>
            </div>
            <div>
                <input type="radio" name="fraga1" value="Victor" id="">
                <label for="Victor">Victor</label>
            </div>
            <div>
                <input type="radio" name="fraga1" value="Arvid" id="">
                <label for="Arvid">Arvid</label>
            </div>
            <input type="hidden" name="name" value="<?php echo $_POST["name"]; ?>">
            <input type="hidden" name="epost" value="<?php echo $_POST["epost"]; ?>">
            <input type="hidden" name="pw" value="<?php echo $_POST["pw"]; ?>">
            <input type="submit" value="Skicka">
        </div>
        <?php }} if(count($_POST) == 4) {?>
            <div id="fraga2">
                Hur gammal är jag?
                <div>
                    <input type="radio" name="fraga2" value="18" id="">
                    <label for="18">18</label>
                </div>
                <div>
                    <input type="radio" name="fraga2" value="19" id="">
                    <label for="19"> 19</label>
                </div>
                <div>
                    <input type="radio" name="fraga2" value="20" id="">
                    <label for="20">20</label>
                </div>
                <div>
                    <input type="radio" name="fraga2" value="21" id="">
                    <label for="21">21</label>
                </div>
                <input type="hidden" name="name" value="<?php echo $_POST["name"]; ?>"/>
                <input type="hidden" name="epost" value="<?php echo $_POST["epost"]; ?>">
                <input type="hidden" name="fraga1" value="<?php echo $_POST["fraga1"]; ?>">
                <input type="hidden" name="pw" value="<?php echo $_POST["pw"]; ?>">
                <input type="submit" value="Skicka">
            </div>
            <?php } if(count($_POST) == 5) {?>
                <div id="fraga3">
                    Vilket lag borde ha vunnit EM 2024?
                    <div>
                        <input type="radio" name="fraga3" value="England" id="">
                        <label for="England">England</label>
                    </div>
                    <div>
                        <input type="radio" name="fraga3" value="Frankrike" id="">
                        <label for="Frankrike">Frankrike (Nej)</label>
                    </div>
                    <div>
                        <input type="radio" name="fraga3" value="Neder" id="">
                        <label for="Neder">Nederländerna</label>
                    </div>
                    <div>
                        <input type="radio" name="fraga3" value="Spanien" id="">
                        <label for="Spanien">Spanien</label>
                    </div>
                    <input type="hidden" name="name" value="<?php echo $_POST["name"]; ?>">
                    <input type="hidden" name="epost" value="<?php echo $_POST["epost"]; ?>">
                    <input type="hidden" name="pw" value="<?php echo $_POST["pw"]; ?>">
                    <input type="hidden" name="fraga1" value="<?php echo $_POST["fraga1"]; ?>">
                    <input type="hidden" name="fraga2" value="<?php echo $_POST["fraga2"]; ?>">
                    <input type="submit" value="Skicka">
                </div>
                <?php }?>
                <br>
            </form>
    <?php
    
if (count($_POST) == 6) {
        
$namn $_POST["name"];
        
$svar1 $_POST["fraga1"];
        
$svar2 $_POST["fraga2"];
        
$svar3 $_POST["fraga3"];
        
$antalRatt 0;
        if(
$svar1 == "Carti"){
            
$antalRatt += 1;
        }
        if(
$svar2 == "18"){
            
$antalRatt += 1;
        }
        if(
$svar3 == "England"){
            
$antalRatt += 1;
        }
        
$meddelande "Hej "$namn"! <br>""Du hade "$antalRatt" av 3 rätt";

        
$mottagare=$_POST["epost"];
        
$rubrik="Resultat på Quiz";
        
$mejlhuvud="From: ".$_POST["epost"]." \nReply-To: sethde@varmdogymnasium.se";
        
mail($mottagare$rubrik$meddelande$mejlhuvud);
        echo 
"<p>SKICKAT till ".$_POST["epost"]."</p>";
        echo 
"<p>================================</p>";
    }
    
?>
</body>

</html>