In my code I created chef class which can have three function I have another ItalianChef which inherits chef class and additionally have two function. What I want to do is in a user form user will first choose a chef and choose dish after that I will show which image of the dish user have choosen. If selected chef doesn't have any dish he can cook I will show cannot cook. The problem is how can I call the function in 'chef' and 'ItalianChef' class according to the checkbox choosen from user. here is the code
<?php
class chef{
function makeFrenchFry()
{
echo "made french fry <br>";
?>
<img src="media/frenchfry.gif" alt="">
<?php
}
function makeCrabFry()
{
echo "made crab fry <br>";
?>
<img src="media/crabfry.gif" alt="">
<?php
}
function makeRamen()
{
echo "made ramen <br>";
?>
<img src="media/ramen.gif" alt="">
<?php
}
}
class ItalianChef extends chef{
function makeLasagna()
{
echo "made lasagna <br>";
?>
<img src="media/lasagna.gif" alt="">
<?php
}
function makeRatatouille()
{
echo "made ratatouille". "</br>";
?>
<img src="media/ratatouille.gif" alt="">
<?php
}
}
$jhon = new chef();
// $jhon->makeFrenchFry();
// $jhon->makeCrabFry();
// $jhon->makeRamen();
$marconi = new ItalianChef();
// $marconi->makeLasagna();
// $marconi->makeRatatouille();
if(isset($_POST['submit'])) {
if(isset($_POST['oneChef'])) {
if(isset($_POST['frenchfry'])
||isset($_POST['crabfry'])
||isset($_POST['ramen'])
||isset($_POST['lasagna'])
||isset($_POST['ratatouille'])
) {
$chefType = $_POST['oneChef'];
$frenchfry = $_POST['frenchfry'];
$crabfry = $_POST['crabfry'];
$ramen = $_POST['ramen'];
$lasagna = $_POST['lasagna'];
$ratatouille = $_POST['ratatouille'];
}else{
echo "select one dish";
}
} else{
echo "select one chef";
}
}
?>
<form action="chef.php" method="post">
<p>Please select your Chef</p>
<input type="radio" id="chef" name="oneChef" value="chef">
<label for="chef">chef</label><br>
<input type="radio" id="ItalianChef" name="oneChef" value="ItalianChef">
<label for="ItalianChef">ItalianChef</label><br>
<input type="checkbox" id="frenchfry" name="frenchfry" value="frenchfry">
<label for="frenchfry"> frenchfry</label><br>
<input type="checkbox" id="crabfry" name="crabfry" value="crabfry">
<label for="crabfry"> crabfry</label><br>
<input type="checkbox" id="ramen" name="ramen" value="ramen">
<label for="ramen"> ramen</label><br><br>
<input type="checkbox" id="lasagna" name="lasagna" value="lasagna">
<label for="lasagna"> lasagna</label><br><br>
<input type="checkbox" id="ratatouille" name="ratatouille" value="ratatouille">
<label for="ratatouille"> ratatouille</label><br><br>
<input type="submit" value="Submit" name="submit">
</form>
Aucun commentaire:
Enregistrer un commentaire