Esempio n. 1
0
function registerDiver()
{
    global $db, $first, $last, $phone, $address, $city, $state, $zip, $email;
    if (validateForm($first, $last, $email)) {
        $SQLstring = "INSERT INTO divers VALUES (NULL, '{$first}', '{$last}', '{$phone}', '{$address}', '{$city}', '{$state}', '{$zip}', '{$email}')";
        $result = $db->exec($SQLstring);
        if ($result < 1) {
            $errors = $db->errorInfo();
            $error = $errors[2];
            include 'error.php';
            exit;
        }
    } else {
        die("<p>You must supply a first name, last name and email address to register! Click your browser's Back button to return to the previous page.</p>");
    }
}
 public static function add($title, $content)
 {
     try {
         // После окончания процедуры валидации проверяем были ли занесены какие-то сообщения об ошибках. Если да то «бросаем» подготовленный объект исключения.
         // Для отлова исключения используем два блока catch: для FormFieldsListException и для всех остальных исключений. Это позволяет задать различные виды действий при возникновении различных типов исключений.
         function validateForm($title, $content)
         {
             $e = new FormFieldsListException();
             if (strlen($title) < 5) {
                 $e[] = 'Слишком короткий заголовок!';
             }
             if (strlen($content) < 100) {
                 $e[] = 'Слишком короткое содержание!';
             }
             if ((bool) $e->current()) {
                 throw $e;
             }
         }
         try {
             validateForm($title, $content);
         } catch (FormFieldsListException $error) {
             echo '<b>Что-то пошло не так...</b>:<br />';
             foreach ($error as $e) {
                 echo $e . '<br />';
                 $error::logWriter($e);
             }
             die('<a href="?ctrl=Articles&action=new">Попробуйте заново, сэр!</a>');
         } catch (Exception $error) {
             echo 'Not validation error! ' . $error->getMessage();
         }
         $sth = self::getDbh()->prepare('INSERT INTO ' . static::$table . ' (`title`, `content`) VALUES (:title, :content)');
         $sth->bindParam(':title', $title);
         $sth->bindParam(':content', $content);
         $sth->execute();
     } catch (PDOException $e) {
         echo $e->getMessage();
     }
 }
Esempio n. 3
0
 $problems = false;
 $error_message = "";
 $errorCounter = 0;
 function validateForm($form_element, $errorMessage)
 {
     if (empty($form_element)) {
         $problems = true;
         $errorCounter++;
         return "<li class='error'>{$errorMessage}</li>";
     }
     return "";
 }
 //Check if any required fields are empty
 $error_message .= validateForm($_POST['project_name'], "Please give your project a name.");
 $error_message .= validateForm($_POST['project_description'], "Please give your project a description.");
 $error_message .= validateForm($_POST['project_loc'], "Please give your project a location.");
 if ($_POST['hidden_loc_lat'] == 0) {
     $problems = true;
     $errorCounter++;
     $error_message .= "<li class='error'>Please provide a valid location.</li>";
 }
 //Validate date
 if (isset($_POST['project_date'])) {
     $dateRegExp = '/^((((0[13578])|([13578])|(1[02]))[\\/](([1-9])|([0-2][0-9])|(3[01])))|(((0[469])|([469])|(11))[\\/](([1-9])|([0-2][0-9])|(30)))|((2|02)[\\/](([1-9])|([0-2][0-9]))))[\\/]\\d{4}$|^\\d{4}$/';
     if (empty($_POST['project_date'])) {
         $problems = true;
         $error_message .= '<li class="error">Please enter a date for your project.</li>';
     } elseif (!preg_match($dateRegExp, $_POST['project_date'])) {
         $problems = true;
         $error_message .= '<li class="error">Please enter a valid date for your project (mm/dd/yyyy).</li>';
     }
Esempio n. 4
0
 $error_message = "";
 $errorCounter = 0;
 function validateForm($form_element, $errorMessage)
 {
     if (empty($form_element)) {
         $problems = true;
         $errorCounter++;
         return "<li class='error'>{$errorMessage}</li>";
     }
     return "";
 }
 //Check if any required fields are empty
 $error_message .= validateForm($_POST['story_topic'], "Please give your story a topic.");
 $error_message .= validateForm($_POST['story_headline'], "Please give your story a headline.");
 $error_message .= validateForm($_POST['story_text'], "Please provide a story to go with your headline.");
 $error_message .= validateForm($_POST['story_loc'], "Please give your story a location.");
 if ($_POST['hidden_loc_lat'] == 0) {
     $problems = true;
     $errorCounter++;
     $error_message .= "<li class='error'>Please provide a valid location.</li>";
 }
 /*/Validate date
 	    $dateRegExp = '/^((((0[13578])|([13578])|(1[02]))[\/](([1-9])|([0-2][0-9])|(3[01])))|(((0[469])|([469])|(11))[\/](([1-9])|([0-2][0-9])|(30)))|((2|02)[\/](([1-9])|([0-2][0-9]))))[\/]\d{4}$|^\d{4}$/';
 	    if (empty($_POST['story_date'])) {
 	        $problems = true;
 	        $error_message .= '<li>Please enter a date for your story.</li>';
 	    } elseif (!preg_match($dateRegExp, $_POST['story_date'])) {
 	    	$problems = true;
     		$error_message .= '<li>Please enter a valid date for your story (mm/dd/yyyy).</li>';
 		}*/
 /*************************If no problems execute query*****************/
Esempio n. 5
0
<?php

require_once "lib/common.php";
$defaults = array('name' => '', 'text' => '');
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $errors = validateForm();
    if (count($errors)) {
        if (isset($_POST['name'])) {
            $defaults['name'] = $_POST['name'];
        }
        if (isset($_POST['text'])) {
            $defaults['text'] = $_POST['text'];
        }
    } else {
        if (!file_exists(FILES_FOLDER . DIRECTORY_SEPARATOR . $_POST['name'] . "." . $_POST['type'])) {
            $fh = fopen(FILES_FOLDER . DIRECTORY_SEPARATOR . $_POST['name'] . "." . $_POST['type'], 'w');
            fwrite($fh, $_POST['text']);
            fclose($fh);
            header("Location: index.php");
            exit;
        } else {
            if (isset($_POST['file'])) {
                $fh = fopen(FILES_FOLDER . DIRECTORY_SEPARATOR . $_POST['file'], 'w');
                fwrite($fh, $_POST['text']);
                fclose($fh);
                header("Location: index.php");
                exit;
            }
        }
    }
} else {
Esempio n. 6
0
        $errorFields[] = 'email';
    }
    if (strstr($question, 'http:') != false || strstr($question, 'href=') != false) {
        $errorFound = true;
        $errorFields[] = 'question';
    }
    // If any errors were found, then return false.  Othwerwise, return true.
    if ($errorFound) {
        return false;
    }
    return true;
}
// Check to see if the form has been submitted
if (isset($_POST['submitted'])) {
    // Check to see if the form is valid
    validateForm();
    if (!$errorFound) {
        // If the form passes validation, then email the form to the appropriate address.
        // Create variables necessary for sending the form information and fill the body of the eamil with the appropriate information.
        $body .= "\nThe information provided in this email was submitted from bevello.com.\n";
        $body .= "A visitor has a question about the following product:\n\n\n";
        $body .= "PRODUCT NAME:  " . $product_name . "\n";
        $body .= "PRODUCT URL:  " . urldecode($product_url) . "\n\n";
        $body .= "VISITOR'S NAME:  " . $user_name . "\n";
        $body .= "EMAIL:  " . $email . "\n\n";
        $body .= "QUESTION:\n" . $question;
        $body .= "\n\n\n";
        $body .= "-- End of Message.";
        // Create variables necessary for sending the form information and fill the body of the email with the appropriate information.
        $toAddress = "*****@*****.**";
        $bccToAddress = "*****@*****.**";
Esempio n. 7
0
                 // on a eu un probleme de recuperation des champs on initialise une erreur
                 $erreur = "Aucune données n a été envoyez ressayez svp!";
             }
         } else {
             // et enfin la dernière erreur possible le format n est pas valide
             // le format est aussi verifier coter client avec javascript il y a donc peut de chance d arriver
             // dans se cas
             $erreur = "Attention les lien videos doivent etres au format embed recommencer!";
         }
     }
 } else {
     //ici pas de value dans l input cacher on en est en creation !!
     // si on a quelque chose en post on le recupere et crée un tableau contenant $_FILES et $_POST
     $valeurTableau = array_merge($_POST, $_FILES);
     // maintenant qu on a un seul tableau on l envoie avec celui de regle a la fonction de validation
     $validationFormulaire = validateForm($valeurTableau, $regles);
     /*la on envoie pour verification*/
     // on place les differne éléments du tableau retourne dans des variables
     $erreur = $validationFormulaire['erreur'];
     $erreurChampsForms = $validationFormulaire['erreursChamps'];
     $valeursTableauForm = $validationFormulaire['valeursNettoyees'];
     // je reformate mes données apres les avoir verifier afin quelle soit en accord  avec
     // ce qui est attendu en bdd
     $valeursTableauForm['duree-min'] = modifStringToInt($valeursTableauForm['duree-min']);
     $valeursTableauForm['sortie'] = modifStringToInt($valeursTableauForm['sortie']);
     $valeursTableauForm['titre'] = modifTitreForAjout($valeursTableauForm['titre']);
     // la j initialise un tableau contenant les valeurs dites "bonnes" qui me serviront
     // pour le pre remplissage des inputs en cas d erreurs
     if (count($erreurChampsForms > 0)) {
         $_SESSION['erreurInsert'] = creaTabForInput($valeursTableauForm, $erreurChampsForms);
         $_SESSION['erreurInsert']['affiche'] = '';
Esempio n. 8
0
$resultValidateForm;
$result = '';
function validateForm(&$error)
{
    global $number, $numbersArray;
    $error = [];
    if (!validateRequired($number)) {
        $error['number'][] = 'Number can not be null.';
    }
    if (count($numbersArray) > 10) {
        $error['count'][] = 'Number must be 10';
    }
    return empty($error);
}
if (!empty($_POST)) {
    $resultValidateForm = validateForm($validationErrors);
    if ($resultValidateForm) {
        $result .= $number . ' ' . $resultContainer;
        $numberCounter--;
    } else {
        $result = $resultContainer;
    }
    if ($numberCounter == 0) {
        $result = trim($result);
        $numbersArray = preg_split('/\\s/', $result);
        $result = 'Sorted Array: ';
        sort($numbersArray);
        foreach ($numbersArray as $value) {
            $result .= $value . ' ';
        }
        $result .= '&#13;&#10;' . 'Min: ' . $numbersArray[0] . '&#13;&#10;' . 'Max: ' . $numbersArray[9];
        array_push($return_values, "false");
        return $return_values;
    }
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $name = $_POST["event_name"];
    $price = $_POST["event_price"];
    $description = $_POST["event_description"];
    $event_images = $_FILES["event_images"]["name"];
    if (validateForm($event, $name, $price, $description)[1] == "true") {
        echo "<div class='alert alert-danger'>";
        echo "<button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>&times;</span></button>";
        echo "<ul>";
        $errors_length = count(validateForm($event, $name, $price, $description)[0]);
        for ($x = 0; $x < $errors_length; $x++) {
            echo "<li>" . validateForm($event, $name, $price, $description)[0][$x] . "</li>";
        }
        echo "</ul>";
        echo "</div>";
    } else {
        $result_for_event = $event->create_event($name, $description, $price);
        if ($result_for_event == true) {
            $event_id = $event->get_last_id();
            for ($i = 0; $i < count($event_images); $i++) {
                $img_tmp_name = addslashes($_FILES['event_images']['tmp_name'][$i]);
                $img_name = addslashes($event_images[$i]);
                if ($img_tmp_name == "") {
                    $remove_inserted_event = $event->remove_event($event_id["id"]);
                    if ($remove_inserted_event == true) {
                        setcookie("flash_danger", "Please Select Images", time() + 3600);
                        header("Location: new_event.php");
        array_push($return_values, "false");
        return $return_values;
    }
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $name = $_POST["event_name"];
    $price = $_POST["event_price"];
    $description = $_POST["event_description"];
    $event_images = $_FILES["event_images"]["name"];
    if (validateForm($event, $name, $price, $description, $event_field["name"])[1] == "true") {
        echo "<div class='alert alert-danger'>";
        echo "<button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>&times;</span></button>";
        echo "<ul>";
        $errors_length = count(validateForm($event, $name, $price, $description, $event_field["name"])[0]);
        for ($x = 0; $x < $errors_length; $x++) {
            echo "<li>" . validateForm($event, $name, $price, $description, $event_field["name"])[0][$x] . "</li>";
        }
        echo "</ul>";
        echo "</div>";
    } else {
        // Updating Event
        $result_for_event = $event->update_event($name, $description, $price);
        if ($result_for_event == true) {
            if (!empty($_FILES["event_images"]["name"][0])) {
                for ($i = 0; $i < count($event_images); $i++) {
                    $img_tmp_name = addslashes($_FILES['event_images']['tmp_name'][$i]);
                    $img_name = addslashes($event_images[$i]);
                    $img_tmp_name = file_get_contents($img_tmp_name);
                    $img_tmp_name = base64_encode($img_tmp_name);
                    $result_for_event_images = $event->save_event_images($img_tmp_name, $img_name, $event_id);
                    if ($result_for_event_images == false) {
Esempio n. 11
0
            $result .= '&#8457;';
        } else {
            if ($op == 2) {
                $result .= '&#8451;';
            }
        }
    } else {
        $result = false;
    }
    ## return ##
    return $result;
}
$errors = [];
$result = false;
if ($_POST) {
    $result = validateForm($errors);
}
?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <link rel="stylesheet" href="css/index.css">
    </head>
    <body>
    <div>
        <form action="index.php" method="post">
            <div>
                <label for="num1">Temperature:</label>
                <input type="number" id="num1" name="num1" class="<?php 
Esempio n. 12
0
        if (!validatePassword($password2)) {
            $errors['password2'][] = "Password need to consist of one of the three of Capital, \nSmall letters, Digits and Special characters";
        }
        if (validateRequired($password1)) {
            if (!validateMatchingPasswords($password1, $password2)) {
                $errors['password2'][] = "Password do not match!";
            } else {
                $password = md5($password1);
            }
        }
    } else {
        $errors['password2'][] = 'Password needs to be filled!';
    }
}
if ($_POST) {
    validateForm($username, $password1, $password2);
}
?>

<!DOCTYPE html>
<html>
<head>
	<title>Task2</title>
	<style type="text/css">
		label {
			display: block;
		}
		.error input {
			border-color: #ff0000;
		}
		.error p {
Esempio n. 13
0
<?php

require_once 'functions.inc';
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$myEmail = "*****@*****.**";
// Sanitize received values
$name = sanitize($name);
$email = sanitize($email);
$message = sanitize($message);
// Validate the form
if (validateForm($name, $email, $message)) {
    // Send the email
    $success = mail($myEmail, "{$name} ({$email})", $message);
    if ($success) {
        sendReply(200, "Email sent");
    } else {
        sendReply(500, "Failed to send email, please try again later");
    }
} else {
    // The form validation failed
    sendReply(400, "Some fields are empty or contain wrong values");
}
Esempio n. 14
0
//define use of this page to process post action
define('THIS_PAGE', basename($_SERVER['PHP_SELF']));
//include statements
include 'Item.php';
include 'functions.php';
include 'Topping.php';
include 'Order.php';
//object instantiation
$newOrder = new Order();
$items["burrito"] = new Item("Burrito", "Includes awesome sauce!", 7.95, $addOns = ["chips", "rice", "jalapeno"]);
$items["taco"] = new Item("Taco", "Includes cheese and lettuce!", 3.99, $addOns = ["tomato", "cream", "beans"]);
$items["icecream"] = new Item("Fried icecream", "Includes free sprinkles!", 5.0);
$items["milkshake"] = new Item("Milkshake", "Three different flavors", 6.0);
$toppings["tomato"] = new Topping("tomatos", 0.5);
$toppings["cream"] = new Topping("sour cream", 0.99);
$toppings["jalapeno"] = new Topping("jalapeno", 0.5);
$toppings["chips"] = new Topping("potato chips", 3.5);
$toppings["rice"] = new Topping("mexican rice", 0.5);
$toppings["beans"] = new Topping("refried beans", 0.5);
$toppings["syrup"] = new Topping("chocolate syrup", 0.5);
$toppings["double-icecream"] = new Topping("double icecream", 0.5);
/*check for values stored on $_POST and runs the appropiate command*/
if (isset($_POST['next'])) {
    validateForm($_POST, $items, $toppings, $newOrder);
} elseif (isset($_POST['place-order'])) {
    $newOrder->orderSummary($_POST, $items, $toppings);
} elseif (isset($_POST['reset'])) {
    $newOrder->displayOrderForm(' ', $items, $toppings);
} else {
    $newOrder->displayOrderForm(' ', $items, $toppings);
}
        return $return_values;
    }
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $first_name = $_POST["first_name"];
    $last_name = $_POST["last_name"];
    $email = $_POST["email"];
    $password = $_POST["password"];
    $confirm_password = $_POST["confirm_password"];
    if (validateForm($user, $email, $password, $confirm_password)[1] == "true") {
        echo "<div class='alert alert-danger'>";
        echo "<button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>&times;</span></button>";
        echo "<ul>";
        $errors_length = count(validateForm($user, $email, $password, $confirm_password)[0]);
        for ($x = 0; $x < $errors_length; $x++) {
            echo "<li>" . validateForm($user, $email, $password, $confirm_password)[0][$x] . "</li>";
        }
        echo "</ul>";
        echo "</div>";
    } else {
        $pw = str_replace(' ', '', $password);
        // file_get_contents() //SQL Injection defence!
        $image = addslashes($_FILES['profile_image']['tmp_name']);
        $image_name = addslashes($_FILES['profile_image']['name']);
        $image = file_get_contents($image);
        $image = base64_encode($image);
        $current_user_email = $_SESSION["login_user"];
        $result = $user->update_user($first_name, $last_name, $email, $pw, $image, $image_name);
        if ($result == true) {
            $_SESSION["login_user"] = $email;
            setcookie("flash_success", "Profile Updated.", time() + 3600);
Esempio n. 16
0
                return false;
            }
        }
        return true;
    }
    function exportUserData($data_arr)
    {
        $path = 'resource/users.txt';
        $mode = "a";
        $data = implode("\t", $data_arr);
        $data .= "\r\n";
        $myfile = file_put_contents($path, $data, FILE_APPEND);
        if ($myfile === FALSE) {
            return false;
        }
    }
    $isDataValid = validateForm($data_err_arr);
    if ($isDataValid) {
        $isSaved = true;
        $isSaved = exportUserData($data_arr);
        if ($isSaved === true) {
            header('Location:http://localhost/05_Working_with_users_input/index.php');
        } else {
            echo "try again!!!";
            header('Location:http://localhost/05_Working_with_users_input/register.php');
        }
    }
}
?>
	</body>
</html>
Esempio n. 17
0
        $errors['password'][] = 'You must enter the same password twice.';
    } else {
        $password = password_hash($password, PASSWORD_DEFAULT);
    }
}
function correctForm($errors)
{
    global $username, $password;
    $html = '';
    if (empty($errors)) {
        $html = "<p>Your username is: {$username}</p> \n\t\t\t\t<p>and your hashed password is: {$password}</p>";
    }
    return $html;
}
if ($_POST) {
    validateForm($errors);
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Task 2</title>
	<style>
	.error {
		color: red;
	}

	.error input {
		border: 1px solid red;
Esempio n. 18
0
                $errors['password2'][] = 'Password must contain at least 1 non-alphanumeric character.';
            } else {
                if (!validateIdentical($password1, $password2)) {
                    $errors['password2'][] = 'Passwords don\'t match.';
                }
            }
        }
    }
    ## return ##
    return empty($errors) ? true : false;
}
$errors = [];
$check = false;
$encrypted = '';
if ($_POST) {
    $check = validateForm($errors);
    $encrypted = password_hash($password1, PASSWORD_DEFAULT);
}
?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <link rel="stylesheet" href="css/index.css">
    </head>
    <body>
    <div>
        <form action="index.php" method="post">
            <div>
                <label for="username">username:</label>
    header('Pragma: public');
    header('Content-Length: ' . (string) strlen($data));
    echo $data;
    exit(0);
}
ob_start();
include "form.html.inc";
$html = ob_get_contents();
ob_end_clean();
$request = get_magic_quotes_gpc() ? array_map('stripslashes', $_REQUEST) : $_REQUEST;
$validationData['address1'] = array('isRequired', 'type' => 'btcdestination');
$validationData['amount1'] = array('isRequired', 'type' => 'btcamount');
$validationData['address2'] = array('type' => 'btcdestination');
$validationData['amount2'] = array('type' => 'btcamount');
$validationData['address3'] = array('type' => 'btcdestination');
$validationData['amount3'] = array('type' => 'btcamount');
if (isset($request['submit'])) {
    $formErrors = validateForm($request, $validationData);
    if (count($formErrors) == 0) {
        $info = createPaymentRequest($request, $formErrors);
    }
    if (count($formErrors) == 0) {
        $html = preg_replace('/<span class="result">[^<]*/', '<span class="result">' . $info, $html);
        // Normally there would be code here to process the form
        // and redirect to a thank you page...
        // ... but for this example, we just always re-display the form.
    }
} else {
    $formErrors = array();
}
echo fillInFormValues($html, $request, $formErrors);
Esempio n. 20
0
                    }
                    echo "</td></tr></table>\n";
                    $lastDate = $evtDate;
                }
            }
        }
    } else {
        echo $xx['sch_no_results'] . "\n";
    }
    echo "</div>\n";
}
//control logic
$msg = '';
//init
if (isset($_POST["search"])) {
    $msg = validateForm();
}
echo "<p class='error'>{$msg}</p>\n";
if (isset($_POST["search"]) and !$msg) {
    searchText();
    //search
    echo "<div class='scrollBoxSh'>\n";
    showMatches();
    //show results
    echo "</div>\n";
} else {
    echo "<div class='scrollBoxAd'>\n\t\t<aside class='aside'>\n{$xx['sch_instructions']}\n</aside>\n\t\t<div class='centerBox'>\n";
    searchForm();
    //define search
    echo "</div>\n</div>\n";
}
Esempio n. 21
0
        }
    }
    function createUser()
    {
        global $mysqli;
        $updatequery = "INSERT INTO users (username, password) VALUES (?, ?)";
        if ($update = $mysqli->prepare($updatequery)) {
            $username = trim($_POST['user']);
            $password = hash('sha256', $_POST['pass']);
            $update->bind_param("ss", $username, $password);
            $update->execute();
            $update->close();
            return true;
        }
    }
    if (!validateForm()) {
        // foutmelding incorrecte invoer
        $message = "uw gebruikers informatie is incompleet of onjuist ingevuld!";
    } elseif (userAlreadyExists()) {
        // foutmelding
        $message = "uw gebruiker is helaas al bij ons bekent!";
    } elseif (!createUser()) {
        // foutmelding
        $message = "Er is iets misgegaan met het aanmaken van uw user. Probeer het opnieuw";
    } else {
        header("location: thankyou.php");
    }
}
?>

<!DOCTYPE html>
Esempio n. 22
0
        }
    }
    if (!validateRequired($gender)) {
        $errors['gender'][] = 'Gender is required';
    }
    if (!validateRequired($formOfAddress)) {
        $errors['form_of_address'][] = 'Form Of Address is required';
    }
    return empty($errors);
}
function getFieldClass($errors, $field)
{
    return !empty($errors[$field]) ? 'error' : '';
}
if (!empty($_POST)) {
    validateForm($validationErrors);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="reset.css">
<style type="text/css">
	form label:first-child {
		width: 150px;
		display: inline-block;
	}
	
	form > div {
Esempio n. 23
0
                break;
            default:
                $calc = 'ERROR!';
        }
        if (is_float($calc)) {
            $calc = round($calc, 2);
        }
    } else {
        $calc = 'ERROR!';
    }
    return $calc;
}
$calc = '';
$errors = [];
if ($_POST) {
    $calc = validateForm($errors);
}
?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <link rel="stylesheet" href="css/index.css">
    </head>
    <body>
    <div>
        <form action="index.php" method="post">
            <div>
                <label for="num1">1st number:</label>
                <input type="number" id="num1" name="num1" class="<?php