Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html>
- <html>
- <head>
- <style type="text/css">
- .error{
- color: red;
- }
- input::-webkit-outer-spin-button,
- input::-webkit-inner-spin-button {
- -webkit-appearance: none;
- margin: 0;
- }
- }
- </style>
- <meta charset="utf-8">
- <title>Register</title>
- <?php
- session_start();
- $action=$_SERVER["PHP_SELF"];
- $errors= array( "", "", "", "", "", "" );
- $_SESSION['errors'] = $errors; // nomeErr, cognomeErr, emailErr, cod_fisErr, passwordErr, c_passwordErr
- $Nome = $indirizzo = $Cognome = $email = $c_password = $password = $CAP = $Città = $cod_fis ="";
- $servername = "localhost";
- $username = "Concessionario";
- $passwordDB = "rUC1TqQK9wfbShVs";
- $conn = new mysqli($servername, $username, $passwordDB);
- $condition = true;
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- if ($_SERVER["REQUEST_METHOD"] == "POST") {
- ////////////////////////////
- if (empty($_POST["Nome"])) {
- $_SESSION['errors'][0] = "Nome è obbligatorio";
- } else {
- $Nome = test_input($_POST["Nome"]);
- if (!preg_match("/^[a-zA-Z ]*$/",$Nome)) {
- $_SESSION['errors'][0] = "Solo spazi bianchi e lettere sono ammessi";
- }
- }
- ////////////////////////////
- if (empty($_POST["CAP"])) {
- $CAPErr = "CAP è obbligatorio";
- } else {
- $CAP = ($_POST["CAP"]);
- }
- ///////////////////////////
- if (empty($_POST["Cognome"])) {
- $_SESSION['errors'][1] = "Cognome è obbligatorio";
- } else {
- $Cognome = test_input($_POST["Cognome"]);
- if (!preg_match("/^[a-zA-Z ]*$/",$Cognome)) {
- $_SESSION['errors'][1] = "Solo spazi bianchi e lettere sono ammessi";
- }
- }
- //////////////////////////
- if (empty($_POST["email"])) {
- $_SESSION['errors'][2] = "Email è obbligatorio";
- } else {
- $email = test_input($_POST["email"]);
- if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
- $_SESSION['errors'][2] = "Formato E-Mail non valido";
- }
- }
- ////////////////////////////
- if (empty($_POST["cod_fis"]))
- $_SESSION['errors'][3] = "Il codice fiscale è obbligatorio";
- else if (strlen($cod_fis=($_POST["cod_fis"])) < 16) $_SESSION['errors'][3] = "Codice fiscale non valido";
- else
- $cod_fis=($_POST["cod_fis"]);
- ////////////////////////////
- if (empty($_POST["password"])) {
- $_SESSION['errors'][4]= "Password è obbligatorio";
- }
- elseif (empty($_POST["c_password"])) {
- $_SESSION['errors'][5]= "Conferma Password è obbligatorio";
- }
- else{
- if($_POST["c_password"] != $_POST["password"] ){
- $_SESSION['errors'][5]="Le due Password non corrispondono";
- }
- else{
- $password=test_input($_POST["password"]);
- }
- }
- if (empty($_POST["Città"])) {
- $errors['CittàErr'] = "Città è obbligatorio";
- } else {
- $Città = test_input($_POST["Città"]);
- if (!preg_match("/^[a-zA-Z ]*$/",$Città)) {
- $errors['CittàErr'] = "Solo spazi bianchi e lettere sono ammessi";
- }
- }
- $provincia = $_POST['Provincia'];
- $indirizzo = $_POST["indirizzo"];
- /*if (isset($provincia)) {
- //Fix Default selected
- }
- */
- }
- function test_error(){
- if (isset($_POST['Submit'])){
- foreach($_SESSION['errors'] as $x => $x_value) {
- if ($x_value != "") {
- $action=$_SERVER["PHP_SELF"];
- break;
- }
- }
- $action="try.php";
- }
- }
- function test_input($data) {
- $data = trim($data);
- $data = stripslashes($data);
- $data = htmlspecialchars($data);
- return $data;
- }
- ?>
- </head>
- <body>
- <form method="post" id="login" action="<?php test_error(); echo htmlspecialchars($action);?>">
- Nome: <input type="text" maxlength="30" name="Nome" value="<?php echo $Nome; ?>">
- <span class="error"> <?php echo $_SESSION['errors'][0];?></span>
- <br><br>
- Cognome: <input type="text" maxlength="30" name="Cognome" value="<?php echo $Cognome; ?>">
- <span class="error"> <?php echo $_SESSION['errors'][1];?></span>
- <br><br>
- E-Mail: <input type="text" maxlength="40" name="email" value="<?php echo $email; ?>">
- <span class="error"> <?php echo $_SESSION['errors'][2];?></span>
- <br><br>
- Codice Fiscale: <input type="text" maxlength="16" name="cod_fis" value="<?php echo $cod_fis; ?>">
- <span class="error"> <?php echo $_SESSION['errors'][3];?></span>
- <br><br>
- Password: <input type="password" maxlength="32" name="password" value="<?php echo $password; ?>">
- <span class="error"> <?php echo $_SESSION['errors'][4];?></span>
- <br><br>
- Conferma Password: <input type="password" maxlength="32" name="c_password" value="<?php echo $c_password; ?>">
- <span class="error"> <?php echo $_SESSION['errors'][5];?></span>
- <br><br>
- Indirizzo: <input type="text" maxlength="50" name="indirizzo" value="<?php echo $indirizzo; ?>">
- <br><br>
- CAP: <input type="number" name="CAP" maxlength="10" value="<?php echo $CAP; ?>">
- <br><br>
- Città: <input type="text" name="Città" maxlength="30" value="<?php echo $Città; ?>">
- <br><br>
- Provincia <select name="Provincia">
- <?php
- $prov=file("Province.txt");
- for ($i=0; $i<sizeof($prov); $i++) {
- $item=explode('|',$prov[$i]);
- echo "<option value='".$item[0]."'> ".$item[0]."</option>";
- }
- ?>
- </select>
- <br><br>
- <input type="submit" name="Submit" value="Invia"> <input type="reset" name="Reset" value="Reset"> <!--Reset or reload? -->
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement