Question

PHP - Use of classes This is a further development of the previous task, the participant...

PHP - Use of classes

This is a further development of the previous task, the participant registration. You must use the following Participant class.

<?php

class Deltaker
{
        private $etterNavn;
        private $forNavn;
        private $fAar;

        function __construct(string $fornavn, string $etternavn, string $aar) {
            $this->forNavn = $fornavn;
            $this->etterNavn = $etternavn;
            $this->fAar = $aar;
        }

        function hentEtterNavn() : string {
           return $this->etterNavn;
        }
         function hentForNavn() : string {
           return $this->forNavn;
        }
        function hentFAar() :  string{
            return $this->fAar;
        }
        //Setters
        function settForNavn(string $fornavn) {
           $this->forNavn = $fornavn;
        }.
        function settEtterNavn(string $etterNavn) {
            $this->etterNavn = $etterNavn;
        }
        function settFAar(string $aar) {
            $this->fAar = $aar;
        }
}
?>

1. Create the Attendee class in the file Deltaker.class.php.

2. For this class to become known to the PHP participant registration script, it must be included in the script with

3.   require_once ('Deltaker.class.php');

This is the code I have so far in the PHP participant registration script so far :

<!DOCTYPE html>
<html>
<head>
    <title>Deltaker registrering</title>
    <meta charset="utf-8" />
    <link rel="stylesheet" type="text/css" href="layout.css"/>
    <link href="https://fonts.googleapis.com/css?family=Happy+Monkey" rel="stylesheet">
</head>
<body>
<h1>Konferansen IKT i undervisningen</h1>
<h2>Registrering</h2>

<?php

require_once ('Deltaker.class.php');

$validate = false;
$fornavn = "";
$etternavn = "";
$fAr = "";
$aar = date ('Y');

//sjekk at skjema er sendt inn
if(isset($_POST['submit'])) {
    if(is_numeric($_POST['fAar'])){
        print("<h1>Fornavn: " . $_POST['forNavn'] . "</h1>");
        print("<h1>Etternavn: " . $_POST['etterNavn'] . "</h1>");
        print("<h1>Yrke: " . $_POST['yrkesValg'] . "</h1>");


        $validate = true;
        //beregn alder
        $dob=$_POST['fAar'];
        $diff = (date('Y') - date('Y',strtotime($dob)));
        echo "Alder: " . $diff;
        echo "<p>Du er registrert " . date('H:i, jS F Y') . "</p>";

        ;
    } else {
        print("Årstall må være numerisk");
        $validate = false;
        $_POST['forNavn'];
        $_POST ['etterNavn'];

    }
}
if(!$validate) {

?>
<form method="post">
    <label>Fornavn:</label>
    <input type="text" name="forNavn" value="<?php echo $fornavn?>" />
    <label>Etternavn:</label>
    <input type="text" name="etterNavn" value="<?php echo $etternavn?>" />
    <label>Fødselsår:</label>
    <input type="text" name="fAar" size="4"/>
    <label>Yrke:</label>
    <select name="yrkesValg">
        <option value="pizzabaker" <?php if(isset($_POST['yrkesValg']) && $_POST['yrkesValg']== "pizzabaker") echo "selected"; ?>>
            Pizzabaker
        </option>
        <option value="systemutvikler" <?php if(isset($_POST['yrkesValg']) && $_POST['yrkesValg']== "systemutvikler") echo "selected"; ?>>
            Systemutvikler
        </option>
        <option value="arkitekt" <?php if(isset($_POST['yrkesValg']) && $_POST['yrkesValg']== "arkitekt") echo "selected"; ?>>
            Arkitekt
        </option>
        <option value="journalist"<?php if(isset($_POST['yrkesValg']) && $_POST['yrkesValg']== "journalist") echo "selected"; ?>>
            Journalist
        </option>
    </select><br /><br />
    <input type="submit" name="submit" value="Submit">

    <?php
    }

    ?>
</body>
</html>

4. When the form is submitted, a new instance of Participant must be created, then the methods (get) must be used to print the properties for the participant and obtain the year of birth.

5. Add a selection list to the Participant Profession Registration Form and add 6 options.

1. Initially, you can hardcode the selection list with these 6 options, ie with 6 option items.

2. In the next issue, you create an array of the relevant career choices. Then create a foreach loop that prints an option item for each of the career choices in the array.

6. Modify the Participant class with required data members and get & set methods to take care of career choices for participants.

7. When submitting a form, it is now also necessary to print a career choice, use a new method for this.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//Deltaker.class.php

<?php

class Deltaker

{

private $etterNavn;

private $forNavn;

private $fAar;

private $yrkesValg;

function __construct(string $fornavn, string $etternavn, string $aar, string $yrke) {

$this->forNavn = $fornavn;

$this->etterNavn = $etternavn;

$this->fAar = $aar;

$this->yrkesValg = $yrke;

}

function hentEtterNavn() : string {

return $this->etterNavn;

}

function hentForNavn() : string {

return $this->forNavn;

}

function hentFAar() : string{

return $this->fAar;

}

function hentYrkesValg() : string{

return $this->yrkesValg;

}

//Setters

function settForNavn(string $fornavn) {

$this->forNavn = $fornavn;

}

function settEtterNavn(string $etterNavn) {

$this->etterNavn = $etterNavn;

}

function settFAar(string $aar) {

$this->fAar = $aar;

}

function settYrkesValg(string $yrke){

$this->yrkesValg = $yrke;

}

}

?>

//form

<!DOCTYPE html>

<html>

<head>

<title>Deltaker registrering</title>

<meta charset="utf-8" />

<link rel="stylesheet" type="text/css" href="layout.css"/>

<link href="https://fonts.googleapis.com/css?family=Happy+Monkey" rel="stylesheet">

</head>

<body>

<h1>Konferansen IKT i undervisningen</h1>

<h2>Registrering</h2>

<?php

require_once ('Deltaker.class.php');

$validate = false;

$fornavn = "";

$etternavn = "";

$fAr = "";

$aar = date ('Y');

$careerChoices = array("pizzabaker", "systemutvikler", "arkitekt", "journalist");

//sjekk at skjema er sendt inn

if(isset($_POST['submit'])) {

if(is_numeric($_POST['fAar'])){

$obj = new Deltaker($_POST['forNavn'],

$_POST['etterNavn'],

$_POST['yrkesValg'],

$_POST['fAar']);

$validate = true;

print("<h1>Fornavn: " . $obj->hentForNavn() . "</h1>");

print("<h1>Etternavn: " . $obj->hentEtterNavn() . "</h1>");

print("<h1>Yrke: " . $obj->hentYrkesValg() . "</h1>");

//beregn alder

$dob=$obj->hentFAar();

$diff = (date('Y') - date('Y',strtotime($dob)));

echo "Alder: " . $diff;

echo "<p>Du er registrert " . date('H:i, jS F Y') . "</p>";

} else {

print("Årstall må være numerisk");

$validate = false;

$_POST['forNavn'];

$_POST ['etterNavn'];

}

}

if(!$validate) {

?>

<form method="post">

<label>Fornavn:</label>

<input type="text" name="forNavn" value="<?php echo $fornavn?>" />

<label>Etternavn:</label>

<input type="text" name="etterNavn" value="<?php echo $etternavn?>" />

<label>Fødselsår:</label>

<input type="text" name="fAar" size="4"/>

<label>Yrke:</label>

<select name="yrkesValg">

<?php foreach($careerChoices as $career) {?>

<option value="<?php echo $career; ?>" <?php if(isset($_POST['yrkesValg']) && $_POST['yrkesValg']== $career) echo "selected"; ?>>

<?php echo $career; ?>

</option>

<?php } ?>

</select><br /><br />

<input type="submit" name="submit" value="Submit">

<?php

}

?>

</body>

</html>

Add a comment
Know the answer?
Add Answer to:
PHP - Use of classes This is a further development of the previous task, the participant...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • How can I print the Database table in PHP please ? here I have form for name and email, also I have php code that allow...

    How can I print the Database table in PHP please ? here I have form for name and email, also I have php code that allow user to add his name and email to my database, all I need to print my final database when the user click on submit. <form action="" method="post"> <label>Name :</label> <input type="text" name="name" required="required" placeholder="Please Enter Name"/><br /><br /> <label>Email :</label> <input type="email" name="email" required="required" /><br/><br /> <input type="submit" value=" Submit " name="submit"/><br /> </form>...

  • Q1. rewrite the exercise on April 4 by adding the following operations: 1) In the php...

    Q1. rewrite the exercise on April 4 by adding the following operations: 1) In the php script, create an associative array named $order that stores the following values: - the number of cheese toppings; - the number of pepperoni toppings; - the number of ham toppings; - the size of the ordered pizza; - the number of the ordered pizza; - the total cost of the order; - the discount rate; - the total cost after the discount. 2) the...

  • PHP code that is given : <?php // Here is where your preprocessing code goes //...

    PHP code that is given : <?php // Here is where your preprocessing code goes // An example is already given to you for the First Name $fname = $_GET['fname']; ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Exercise 2 - GET Echo</title> <style> body { margin:0; padding:0; font-family: Arial; } form { margin:20px; } input[type="text"], input[type="password"] { width:150px; padding:3px; font-size:1em; } input[type="submit"] { padding:3px; font-size:1em; } label { display:inline-block; width:150px; } .input-container { padding:5px; } </style> </head> <body> <form...

  • PHP Can't get my code to work, what am I doing wrong? <!DOCTYPE html> <html> <head>...

    PHP Can't get my code to work, what am I doing wrong? <!DOCTYPE html> <html> <head> <script> </script> </head> <body> <h2>Temperature Conversion Table</h2> <h4>Enter a starting value in degrees Fahrenheit and an increment value.</h4> <form name="myTemp" onsubmit="convertCelcius()" method="post"> <input type="text" name="temperature"> Enter an value in degrees Fahrenheit<br><br> <input type="radio" name="degIncrement" id="degIncrement5"> Convert in increment in 5 degrees<br> <input type="radio" name="degIncrement" id="degIncrement10"> Convert in increment in 10 degrees <br/><br/><input type="submit" value="Submit"> </form> <?php if( $_POST["temperature"] || $_POST["degincrement"] ) { //get he...

  • Hey Guys I am doing a project and need some help with code in HTML and...

    Hey Guys I am doing a project and need some help with code in HTML and PHP. I need a form made in HTML that can be sent to a specific email through PHP. For some reason the info is not getting sent to my email, even though it says that it was sent. I have some source code here: <?php if(isset($_POST['submit'])) { $name = $_POST['name']; $email = $_POST['email']; $subject = $_POST['subject']; $message = $_POST['message']; $email = mail('MY_EMAIL', $subject, $message,...

  • Create a PHP-backed webpage that ask for a number and calculate is square 10 times. Hint...

    Create a PHP-backed webpage that ask for a number and calculate is square 10 times. Hint 1: <html> <body> <h1>Iteration Program</h1> Today's date: <?php echo date("1 F d, Y"); ?> <h3>Enter a Value to Iterate</h3> <form action="results.php",method=post> <input type="text" name="data"> <p/> <input type="submit" value="Show Results"> </form> </body> </html> Hint 2: <html> <body> <h1>Iteration Results</h1> <b>Here are 10 iterations of the formula:<br/> y=x<sup>2</sup> </b> <p/> <!-- PHP Calculations start here! --> <?php $num = $_POST['data']; //Write your code Here! ?> </body>...

  • LANGUAGE JAVASCRIPT, PHP Need help with PHP and ajax code. The user needs to login but,...

    LANGUAGE JAVASCRIPT, PHP Need help with PHP and ajax code. The user needs to login but, I keep getting an error that I coded "Wrong username and password!" ***PLEASE DONT GIVE ME A NEW CODE THAT IS NOWHERE NEAR THE CODE I SUBMITTED***** PLEASE LOOK AT THE CODE AND SEE ANY ISSUES login.html <!DOCTYPE html> <html> <head> <title>login popup</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <style type="text/css"> body { background-color: white; } </style> </head> <body> <center> <h1 style="text-align: center;"> Login </h1> <form>             Login ID:...

  • For this code below, I need to add the form information to mysql when I click...

    For this code below, I need to add the form information to mysql when I click on submit, at the same time when I click on submit I need to move to another page like Welcome.php WITH NOTE THAT THE ENTERED INFORMATION NOW ALREADY IN DATABASE how can I male that with my code below? THANKS ................................................................................................................................................   <form method="POST"> <div class="container">    <label for="fname"><b>First Name</b></label> <input type="text" placeholder="Enter First Name" name="fname" required> <label for="lname"><b>Last Name</b></label> <input type="text" placeholder="Enter Last Name"...

  • PHP, HTML I have this code in the picture below for a guess game.

    PHP, HTML I have this code in the picture below for a guess game.

  • URGENT HELP NEEDED: JQuery. PLEASE POST SCREEN SHOTS Task 1: Downloading jQuery Right-click the link to...

    URGENT HELP NEEDED: JQuery. PLEASE POST SCREEN SHOTS Task 1: Downloading jQuery Right-click the link to download the uncompressed latest version of jQuery Copy the jQuery.x.x.x.js file in the folder and specified as source file. Task 2: Download and install HTML-Kit 1. Navigate to htmlkit.com. 2. Click Download HTML-Kit 292. After it downloads, launch HKSetup.exe. Choose Full installation (the default) Uncheck Yes, download and install HTML-Kit Tools Trial. 6. Click Next>Finish. Task 3: Creating a Simple jQuery Application Launch HTML-Kit....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT