[PHP] Validare form prenotazione appuntamento tattoo con upload image

Discussione in 'PHP' iniziata da fla88vus, 21 Settembre 2017.

Tag (etichette):
  1. fla88vus

    fla88vus Nuovo Utente

    Registrato:
    20 Settembre 2017
    Messaggi:
    3
    Mi Piace Ricevuti:
    0
    Punteggio:
    1
    Sesso:
    Femmina
    Buongiorno,

    sono nuova nel Forum, e da poco sto approcciando a PHP.
    La questione è la seguente, io ho un form di prenotazione, con campi obbligatori, e checkbox, per l'autorizzazione della maggiore età, e l'upload di un file img formato; jpg, gif, png, jpeg, pdf; un input option value. Il messaggio dovrà contenere tutti i campi compilati dal cliente, includendo il file img allegato, la prenotazione contenente tutti i dati dovrà esser spedita alla mail del negoziante.

    HTML

    <form method="post" action="<? echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data" >
    <input type="text" name="From" value="Your Name" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Your Name';}" required="">
    <input type="email" value="Best email to reach you" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Best email to reach you';}" required="">
    <input type="text" value="Contact No." onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Contact No.';}" required="">

    <br>

    <strong> Place for tattoo </strong>
    <br>

    <select style="width:100%" class="select_form">
    <option value=""> </option>
    <option value="Ankle">Ankle</option>
    <option value="Back - full">Back - full</option>
    <option value="Back - lower">Back - lower</option>
    <option value="Back - upper">Back - upper</option>
    <option value="Behind ear">Behind ear</option>
    <option value="Calf">Calf</option>
    <option value="Chest / sternum">Chest / sternum</option>
    <option value="Foot">Foot</option>
    <option value="Forearm - inner">Forearm - inner</option>
    <option value="Forearm - outer">Forearm - outer</option>
    <option value="Full sleeve">Full sleeve</option>
    <option value="Hand">Hand</option>
    <option value="Hip">Hip</option>
    <option value="Neck">Neck</option>
    <option value="Ribs">Ribs</option>
    <option value="Shin">Shin</option>
    <option value="Shoulder">Shoulder</option>
    <option value="Stomach">Stomach</option>
    <option value="Thigh - back">Thigh - back</option>
    <option value="Thigh - front">Thigh - front</option>
    <option value="Throat">Throat</option>
    <option value="Upper arm - inner">Upper arm - inner</option>
    <option value="Upper arm - outer">Upper arm - outer</option>
    <option value="Wrist">Wrist</option>
    <option value="Other -">Other - </option>
    </select>
    <br>
    <br>
    <strong>Rough Size - Height... cm Width... cm</strong>
    <br>

    <input style ="width:100%" type="text" name="Rough Size" value="Rough Size" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Rough Size ';}" required="">
    <br>
    <br>
    <strong> When would be the ideal time for you to get your tattoo?</strong>
    <br>
    <select style="width:100%" class="select_form">
    <option value=""> </option>
    <option value="Today">Today</option>
    <option value="Next few days">Next few days</option>
    <option value="Within a week">Within a week</option>
    <option value="Within two weeks">Within two weeks</option>
    <option value="Within a month">Within a month</option>
    <option value="Within two months">Within to months</option>
    <option value="After two months">After to months</option>

    </select>
    <br>
    <br>
    <strong>References (images)</strong>
    <br>
    <div style="background-color:#F3F3F3; height:80%; width:100% ; border:dashed;border-color:#9B9B9B";>
    <br>
    <h2 style="color:#9B9B9B; font-size:15px; text-align:center">drop files here or</h2>
    <br>
    <input type="file" value="Select file" name="attachment"style="display: block; margin:0 auto; width:88px" name="foto[]" id="foto[]">
    <br>
    </div>
    <br>
    Accepted file types: jpg, gif, png, jpeg, pdf.
    <br>
    <br>
    <strong>Tattoo Description</strong>
    <br>
    Eg; colour, style, subjects, background etc
    <br>

    <textarea name="message" value="message" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = '';}" required></textarea>
    <br>
    <br>
    <strong>Legal*</strong>

    <input type="checkbox" name="autorizzo" value="y" id="autorizzo_0">
    <br>
    I am 18 years of age (or older) with a valid form of identification
    <br>
    <br>
    <input type="submit" value="Send message" >
    </form>

    PHP

    if (isset($_POST["Send message"])){
    $nome=$_POST['Your Name'];
    $email=$_POST['From'];
    $telephone=$_POST['Contact No.'];
    $autorizzo=$_POST['autorizzo'];
    $message=$_POST['message'];
    $rought=$_POST['Rough Size'];

    $attachment = $_FILES['attachment']['tmp_name'];
    $attachment_type = $_FILES['attachment']['type'];
    $attachment_name = $_FILES['attachment']['name'];

    $intestazioni = "From: " . $email;
    $message = "";

    if (is_uploaded_file($attachment))
    {
    $file = fopen($attachment,'rb');
    $data = fread($file, filesize($attachment));
    fclose($file);
    $data = chunk_split(base64_encode($data));
    $rand = md5(time());
    $boundary = "==Multipart_Boundary_x{$rand}x";

    $intestazioni .= "\nMIME-Version: 1.0\n";
    $intestazioni .= "Content-Type: multipart/mixed;\n";
    $intestazioni .= " boundary=\"{$boundary}\"";

    $messaggio .= "This is a multi-part message in MIME format.\n\n";
    $messaggio .= "--{$boundary}\n";
    $messaggio .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
    $messaggio .= "Content-Transfer-Encoding: 7bit\n\n";
    $messaggio .= $message . "\n\n";
    $messaggio .= "--{$boundary}\n";
    $messaggio .= "Content-Disposition: attachment;\n";
    $messaggio .= " filename=\"{$attachment_name}\"\n";
    $messaggio .= "Content-Transfer-Encoding: base64\n\n";
    $messaggio .= $data . "\n\n";
    $messaggio .= "--{$boundary}--\n";
    }
    else{
    $messaggio = $message;
    }

    if (mail($mail_to , $email, $messagge, $intestazioni))
    {
    echo "Messaggio inviato con successo.";
    }else{
    echo "Si &egrave; verificato un errore nell'invio.";
    }
    }else{



    $mail_to="flaviacardosi@gmail.com";
    $mail_from="$email";// info@cloakanddaggerlondo.co.uk
    $mail_subject="Booking & Enquiries";
    $mail_body="$message";


    $mail_in_html="MIME-Version:1.0\r\n";
    $mail_in_html.="Content-type:text/html;charset=iso-8859-1\r\n";
    $mail_in_html.="From:$mail";

    mail($mail_to,$mail_subject,$mail_body,$mail_in_html);
    }

    Potreste aiutarmi?

    Grazie anticipatamente!

    Flavia
     
Sto caricando...

Condividi questa Pagina