Home Creating a class for user input and passing the value to another object
Reply: 0

Creating a class for user input and passing the value to another object

user4899
1#
user4899 Published in August 15, 2018, 8:44 pm

I have an issue with an app I am writing. It takes a users input from a form then passes this value via _GET to a class. That class then assigns the user input to a variable and then passes it to another object. What I have so far is 3 php files Venue.class.php Concert.class.php and Object.php also a simple html form for user input. I have tried the app as a simple user input without the app.php and it is working so the problem is with my app.php file.

	<form action = "object.php" method = "GET">
	<b>Enter band name : </b>
	<input type="text" name="bandName" />
	<input name="submit" type="submit" value="Click" />
</form>

That is then running to my Object.php file

<?php           

    include "venue.class.php";

    class App {

        function __construct(){

        public $band = $_GET['bandName'];

        function setBandname($userBand) {

                $this->band = $userBand;

        }

        function getBandname(){

                return $this->band;
        }
    }


        $tmpVenue = new Venue;

            //Set Venue Name
            $tmpVenue->SetVenueName('Wembley');

            //Add Concerts To Venue
            $tmpVenue->AddConcert('Rollin\' Empire', '05-02-2018');
            $tmpVenue->AddConcert('Metallica', '06-02-2018');
            $tmpVenue->AddConcert('Led Zeppelin', '07-02-2018');
            $tmpVenue->AddConcert('Rollin\' Empire', '19-02-2018');
            $tmpVenue->AddConcert('Oasis', '23-02-2018');
            $tmpVenue->AddConcert('Liam Gallagher', '30-06-2018');
            $tmpVenue->AddConcert('Muse', '25-03-2018');
            $tmpVenue->AddConcert('Queen', '27-03-2018');
            $tmpVenue->AddConcert('Fangclub', '30-03-2018');
            $tmpVenue->AddConcert('Otherkin', '02-04-2018');

            //Search For Artist In Venue ( Leave Blank To List All )
            $tmpVenue->ListConcertsInVenue($band);
        }

?>

Then the concert.class.php file

<?php 

    class Concert {

                public $Artist = '';
                public $Date = '';

                function SetConcert( $NewArtist = '', $NewDate = '' ) {

                    $this->Artist = $NewArtist;
                    $this->Date = $NewDate;

                }

                function GetArtist() {

                    return $this->Artist;

                }

                function GetDate() {

                    return $this->Date;

                }

            }
?>

The venue.class.php file

 <?php

            include "concert.class.php";

        class Venue {

                    public $VenueName = '';
                    public $ConcertsInVenue = array();

            function SetVenueName( $NewVenue = '' ) {

                        $this->VenueName = $NewVenue;

            }

                    function GetVenueName() {

                        return $this->VenueName;

                    }

                    function AddConcert( $NewArtist = '', $NewDate = '' ) {

                        $NewConcert = new Concert;
                        $NewConcert->SetConcert( $NewArtist, $NewDate );

                        $this->ConcertsInVenue[] = $NewConcert;


                    }

                    function ListConcertsInVenue( $SearchQuery = '' ) {

                        //Assume Results Will Be Filtered
                        $ListAllConcerts = FALSE;

                        //If Search Query Is Blank, List All Concerts
                        if( $SearchQuery == '' ){

                            $ListAllConcerts = TRUE;

                        }

                        echo 'Concerts In '.$this->VenueName.':';

                        //Loop Through All Concerts In This Venue
                        foreach( $this->ConcertsInVenue as $tmpConcert ){

                            if( $SearchQuery == $tmpConcert->GetArtist() || $ListAllConcerts == TRUE ){

                                echo '<p>';
                                echo $tmpConcert->GetArtist().', ';
                                echo $tmpConcert->GetDate();
                                echo '</p>';

                            }

                        }

                    }

            }

    ?>

I'm really having trouble with getting that user data from the form into a variable and processing it in a class then passing that value into $tmpVenue->ListConcertsInVenue($band);

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.293736 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO