In: Computer Science
PHP
You will be using the object oriented features of PHP to design a music album processing page.
First you will build a form page called addAlbum.php. This form will contain text fields for album title, artist, publisher (Sony, BMI, etc.) and genre. Add two more fields of your choice. You will post this form to the file process.php.
If all the fields have values, we will create a new Album object and print the details of the object. You will need to create an Album class that has private instance variables for all the fields just described. Your constructor should simply echo to the screen "Album created." If the user missed some of the form, give them a link to go back and fix.
Generate standard getters/setters
You will need to create __get and __set functions (magic functions) to allow us to set the properties of the instance variables from outside the class. You will also create a function (or method) called __toString() in the class. Calling this will return a formatted string of all the details for the album. Store the class in album.class.php.
Include a hyperlink back to add another album.
Sample output could look like this:
Album Created
Album Title: Blaze of Glory
Artist: Jon Bon Jovi
Publisher: ASCAP
Genre: Rock
Custom Field: stuff
Another Custom Field: stuff
Add another album! (This is an hyperlink to add another album)
Requirements
i. Comments on all pages, proper page names (as requested),
aligned code, overall effort
ii. addAlbum.php page is complete - doctype, complete html
structure and some instructions that give the user some indication
of what they are to do
iii. album.class.php - contains code to define album class - as
well as documentation/comments to outline how to use - see
requirements for details (private vars, constructor, magic
methods(__get(),__set() and __toString functions)
iv. Some type of validation used so that user knows about
errors
v. Styles for all pages: Use an external stylesheet for all styles.
All page content should be in a div with an id set to 'container',
650px wide and the content centered.
vi.The container div should also be centered on the screen
(horizontally). The constructor text should be echoed using an
<h3> tag. Please bold all labels as displayed above.
vii. Use the Button class to print the submit button on the form
page addAlbum.php.
Add Album.php
<!DOCTYPE html>
<html>
<body>
<h1>Add Album</h1>
<form action="/process.php" method="get"
target="_blank">
<label> album title:</label>
<input type="text"
name="title"></input><br/><br/>
<label> artist:</label>
<input type="text"
name="artist"></input><br/><br/>
<label> publisher (Sony, BMI, etc.):</label>
<input type="text"
name="publisher"></input><br/><br/>
<label> genre:</label>
<input type="text"
name="genre"></input><br/><br/>
<input type="button" name="submit"
value="submit"></input>
</form>
<p>Click on the submit button, and the input will be sent to a page called "process.php".</p>
</body>
</html>
Process.php
<!DOCTYPE html>
<h1>processs.php</h1>
<?php
$title= $_POST['title'];
$artist= $_POST['artist'];
$publisher=$_POST['publisher'];
$genre=$_POST['genre'];
echo
"Title:".$title."\nArtist:".$artist."\nPublisher:".$publisher."\nGenre:".$genre;
?>
AlbumClass.php
<!DOCTYPE html>
<html>
<body>
<h1>Album Class.php</h1>
<?php
class Album{
var $title;
var $artist;
var $publisher;
var $genre;
function __construct($title,$artist,$publisher,$genre) {
$this->title = $title;
$this->artist = $artist;
$this->publisher = $publisher;
$this->genre = $genre;
echo "Album created.";
}
//<p><a href="addAlbum.php">Visit: you want any
changes!</a></p>
public function setTitle($title){
$this->title = $title;
}
public function getTitle(){
return $this->title;
}
public function setArtist($artist){
$this->artist = $artist;
}
public function getArtist(){
return $this->artist;
}
public function setPublisher($publisher){
$this->publisher = $publisher;
}
public function getPublisher(){
return $this->publisher;
}
public function setGenre($genre){
$this->genre = $genre;
}
public function getGenre(){
return $this->genre;
}
public function __toString() {
return "\nAlbum Title:".$title."\nArtist:".$artist."
\nPublisher:".$publisher."\nGenre:".$genre;
}
}
?>
<p><a href="/AddAlbum.php">Add Another
album!</a></p>
</body>
</html>
Output:
I hope this will help if not please comment below i will help you!!
Please do not forget to Upvote the answer!
Happy Learning!!