esercizi su form, php

This commit is contained in:
2014-11-07 21:34:49 +01:00
parent 3924e6bf32
commit 8f485b73b3
9 changed files with 510 additions and 0 deletions

77
php10.php Normal file
View File

@@ -0,0 +1,77 @@
<?php
require_once ('functions.php');
include('header.html');
///////////////////////////
echo<<<_css
<style>
input:valid {
background-color:green;
}
input:invalid {
background-color:red;
}
input:in-range {
font-size:20pt;
}
input:required {
color:red;
}
input:optional {
color:blue;
}
input:active {
outline: 5px black solid;
}
input:focus {
outline: 5px yellow solid;
}
#a[placeholder="mario"][required]{
outline: 5px red solid;
}
</style>
_css;
echo "\n";
///////////////////////////
echo<<<_html
<a href="php9.php"><img src="sky.jpg" usemap="#mario" alt="image" /></a>
<map name="mario">
<area href="a.html" shape="rect" coords="0,0,100,100" alt="1 area"/>
<area href="b.html" shape="rect" coords="100,0,200,100" alt="2 area"/>
<area href="def.html" shape="default" alt="other"/>
</map>
_html;
include ('footer.html');
?>

75
php5.php Normal file
View File

@@ -0,0 +1,75 @@
<?php
require_once ('functions.php');
include('header.html');
///////////////////////////
echo<<<_css
<style>
select {
width:100px;
}
</style>
_css;
echo "\n";
///////////////////////////
if ($_GET == null){
echo<<<_html
<form method="get">
<select name="ale[]" size="5">
<optgroup label="art">
<option value="a">asdsa</option>
</optgroup>
<optgroup label="a1t">
<option value="a" >ai</option>
<option value="a" >ai</option>
</optgroup>
</select>
<textarea cols="20" rows="5" name="story" wrap="soft">yeah</textarea>
<input type="submit"/>
</form>
_html;
}else {
print_r($_GET);
}
include ('footer.html');
?>

57
php6.php Normal file
View File

@@ -0,0 +1,57 @@
<?php
require_once ('functions.php');
include('header.html');
///////////////////////////
echo<<<_css
<style>
select {
width:100px;
}
</style>
_css;
echo "\n";
///////////////////////////
if (!isset($_GET['attributes']) ){
echo <<<_html
<form method="GET">
Select your personality attributes:<br />
<input type="checkbox" name="attributes[]" value="perky" /> Perky<br />
<input type="checkbox" name="attributes[]" value="morose" /> Morose<br />
<input type="checkbox" name="attributes[]" value="thinking" /> Thinking<br />
<input type="checkbox" name="attributes[]" value="feeling" /> Feeling<br />
<input type="checkbox" name="attributes[]" value="thrifty" />Spend-thrift<br />
<input type="checkbox" name="attributes[]" value="shopper" /> Shopper<br />
<br />
<input type="submit" name="s" value="Record my personality!" />
</form>
_html;
}else{
print_r($_GET);
}
include ('footer.html');
?>

51
php7.php Normal file
View File

@@ -0,0 +1,51 @@
<?php
require_once ('functions.php');
include('header.html');
///////////////////////////
echo<<<_css
<style>
select {
width:100px;
}
</style>
_css;
echo "\n";
///////////////////////////
if (count($_FILES)==0){
echo "<form action=\"",$_SERVER['PHP_SELF'],"\" method=\"POST\" enctype=\"multipart/form-data\" > ";
echo "<input type=\"file\" name=\"gino\" >";
echo "<input type=\"submit\">";
echo "</form>";
}else {
$file = $_FILES['gino']['name'];
move_uploaded_file($_FILES['gino']['tmp_name'], $_SERVER["DOCUMENT_ROOT"]."uploaded/$file");
}
include ('footer.html');
?>

85
php8.php Normal file
View File

@@ -0,0 +1,85 @@
<?php
require_once ('functions.php');
include('header.html');
///////////////////////////
echo<<<_css
<style>
input:valid {
background-color:green;
}
input:invalid {
background-color:red;
}
input:in-range {
font-size:20pt;
}
input:required {
color:red;
}
input:optional {
color:blue;
}
input:active {
outline: 5px black solid;
}
input:focus {
outline: 5px yellow solid;
}
#a[placeholder="mario"][required]{
outline: 5px red solid;
}
</style>
_css;
echo "\n";
///////////////////////////
echo<<<_html
<form>
<input type = "text" placeholder = "nome" required > Nome </input>
<br>
<input type = "text" placeholder = "cnome" > cNome </input>
<br>
<input type = "number" placeholder = "eta" required min=18 max=150 > Eta </input>
<br>
<input type = "number" id="a" placeholder = "mario" required min=18 max=150 > Eta </input>
<br>
<input type ="submit" name="s" value ="vai"/>
</form>
_html;
include ('footer.html');
?>

77
php9.php Normal file
View File

@@ -0,0 +1,77 @@
<?php
require_once ('functions.php');
include('header.html');
///////////////////////////
echo<<<_css
<style>
input:valid {
background-color:green;
}
input:invalid {
background-color:red;
}
input:in-range {
font-size:20pt;
}
input:required {
color:red;
}
input:optional {
color:blue;
}
input:active {
outline: 5px black solid;
}
input:focus {
outline: 5px yellow solid;
}
#a[placeholder="mario"][required]{
outline: 5px red solid;
}
</style>
_css;
echo "\n";
///////////////////////////
print_r($_GET);
foreach ($_GET as $key => $value) {
$a= explode(",",$key);
}
echo $a[0];echo "<br>";echo $a[1];echo "<br>";
echo<<<_html
<a href="php9.php"><img src="sky.jpg" ismap alt="image" /></a>
_html;
include ('footer.html');
?>

BIN
sky.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

62
sticky.php Normal file
View File

@@ -0,0 +1,62 @@
<html>
<head><title>Pizzeria on-line</title></head>
<body>
<?php
ini_set('display_errors', 'On');
// Si prelevano i valori, se esistono
if (!isset($_GET['gusti']))
{ $scelte = array(); }
else
$scelte = $_GET['gusti'];
// function make_checkboxes ($name, $query, $options)
// crea codice HTML per checkboxe con lo stesso nome
// $name = nome del campo checkbox della form ([] aggiunto dalla funzione)
// $query = parametri attuali della richiesta GET
// $options = array di value=>label per le checkbox
// tutte le opzioni presenti in $query saranno marcate come checked
function make_checkboxes ($name, $query, $options) {
foreach ($options as $value => $label) {
// printf('<input type="checkbox" name="%s[]" value="%s" ', $name, $value);
echo "<input type=\"checkbox\" name=\"$name","[]\" value=\"$value\" ";
if (in_array($value, $query)) { echo "checked "; }
echo "> $label <br>\n";
}
}
// la lista di valori e label per le caselle di spunta
$tipi_condimento = array(
'peperoni' => 'Peperoni a listarelle',
'funghi' => 'Funghi trifolati',
'salame' => 'Salame piccante',
'ricotta' => 'Ricotta al forno',
'salsiccia' => 'Salsiccia sbriciolata',
'broccoli' => 'Broccoli saltati in padella',
'pomodorini' => 'Pomodorini a dadini',
'rughetta' => 'Rughetta selvatica'
);
?>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="GET">
Scegli i gusti della tua pizza:<br />
<?php make_checkboxes('gusti', $scelte, $tipi_condimento); ?>
<br>
<input type="submit" name="s" value="Ordina la pizza!">
</form>
<?php
//if (array_key_exists('s', $_GET) && count($scelte)>0) {
if (count($scelte)>0) {
echo "Hai scelto una pizza con i seguenti condimenti:<br>";
foreach ($scelte as $condimento)
echo $tipi_condimento[$condimento], "<br>";
}
?>
</body>
</html>

26
test_5.html Normal file
View File

@@ -0,0 +1,26 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Example</title>
<meta name="author" content="Adam Freeman"/>
<meta name="description" content="A simple example"/>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
</head>
<body>
<header>
<h1>Things I like</h1>
<nav>
<ul>
<li>
<a href="fruits.html" target="myframe">Fruits I Like</a>
</li>
<li>
<a href="activities.html" target="myframe">Activities I Like</a>
</li>
</ul>
</nav>
</header>
<iframe name="myframe" width="300" height="100">
</iframe>
</body>
</html>