Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    Form in php: flag obbligatorio su autorizzo

    Mi è venuta un'altra domanda , come posso mettere obbligatorio il flag dell'autorizzazione ai dati inviati ecct...nel form php?

    Nel codice html ce l'ho messo, ma NON so come scrivere il codice di comando in php, mi potete aiutare ? NON so comunque se va bene anche in html:

    <input name="autorizzo2" type="checkbox" id="autorizzo2" value="checkbox" checked>


    --------------------------------------------------------------
    CODICE HTML:


    <form action="http://www.miosito/send_info.php" method="post" enctype="multipart/form-data" name="INFO - title" id="INFO - title">


    Or Compile this form</p>


    (I dati con l’asterisco sono obbligatori)</p>


    *first
    <label>
    <input name="first" type="text" id="first" maxlength="20">
    </label>
    *last
    <label>
    <input name="last" type="text" id="last" maxlength="20">
    </label>
    </p>


    address
    <label>
    <input name="address" type="text" id="address" value="" size="40" maxlength="50">
    </label>
    n .
    <label>
    <input name="number" type="text" id="number" size="5" maxlength="5">
    </label>
    </p>


    city
    <label>
    <input name="city" type="text" id="city" size="30" maxlength="20">
    </label>
    state
    <label>
    <input name="state" type="text" id="state" size="30" maxlength="10">
    </label>
    </p>


    *email
    <label>
    <input name="email" type="text" id="email" size="30" maxlength="50">
    </label>
    *website
    <label>
    <input name="website" type="text" id="website" size="40" maxlength="50">
    </label>




    *request</p>



    <label>
    <textarea name="request" cols="60" rows="10" wrap="VIRTUAL" id="request"></textarea>
    </label>
    </p>


    <label>
    <input name="inviomail" type="checkbox" id="inviomail" value="s" checked>
    Compila i dati e invia il tutto alla tua casella di posta</label>


    </p>



    <input name="autorizzo2" type="checkbox" id="autorizzo2" value="checkbox" checked>
    Autorizzo il trattamento dei miei dati personali</p>



    <input name="send2" type="submit" id="send2" value="send">
    [img]/images/collection_images/banner_120x60_send_jpg.jpg[/img]
    </p>


    </p>


    <label>
    <label>
    <input name="reset " type="reset" id="reset " value="reset">
    </label></label>
    [img]/images/collection_images/banner_120x60_reset.jpg[/img]</p>
    <blockquote>
    <blockquote>
    <h5> </h5>
    </blockquote>
    </blockquote>


    </p>
    </form>


    -----------------------------------

    CODICE PHP:


    <?Php

    if(isset($_POST['email'])) {

    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "info@miosito.com"; $email_subject = "Informazioni Generali - MIOSITO ";
    function died($error) {

    // your error code can go here
    echo "We are very sorry, but there were error(s) found with the form you submitted. ";
    echo "These errors appear below.

    "; echo $error."

    ";
    echo "Please go back and fix these errors.

    ";
    die(); }

    // validation expected data exists

    if(!isset($_POST['first']) ||
    !isset($_POST['last']) ||
    !isset($_POST['address']) ||
    !isset($_POST['number']) ||
    !isset($_POST['city']) ||
    !isset($_POST['state']) ||
    !isset($_POST['email']) ||
    !isset($_POST['website']) ||
    !isset($_POST['request'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); }
    if(isset($_POST['inviomail'] && $_POST['inviomail']=='s')) //allora devo inviare la mail

    $first = $_POST['first']; // required
    $last = $_POST['last']; // required
    $email = $_POST['email']; // required
    $website = $_POST['website']; // required
    $request = $_POST['request']; // required


    $error_message = ""; $email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+.[A-Z]{2,4}$"; if(!eregi($email_exp,$email)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.
    '; }
    $string_exp = "^[a-z .'-]+$"; if(!eregi($string_exp,$first)) {
    $error_message .= 'The First Name you entered does not appear to be valid.
    '; } if(!eregi($string_exp,$last)) {
    $error_message .= 'The Last Name you entered does not appear to be valid.
    '; }


    function clean_string($string) {
    $bad = array("content-type","bcc:","to:","cc:","href");
    return str_replace($bad,"",$string);
    }
    if(strlen($comments) < 2)

    $email_message .= "first: ".clean_string($first)."\n";
    $email_message .= "last : ".clean_string($last)."\n";
    $email_message .= "address: ".clean_string($address)."\n";
    $email_message .= "number: ".clean_string($number)."\n";
    $email_message .= "city: ".clean_string($city)."\n";
    $email_message .= "state: ".clean_string($state)."\n";
    $email_message .= "email: ".clean_string($email)."\n";
    $email_message .= "website: ".clean_string($website)."\n";
    $email_message .= "request: ".clean_string($request)."\n";

    // create email headers

    $headers = 'From: '.$_POST['email']."\r\n". 'Reply-To: '.$_POST['email']."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers);

    ?>

    <body background="images/collection_images/sfondo_orange_1000_20_jpg.jpg">

    </p><table width="307" border="3" align="center" bordercolor="#660000" bgcolor="#000000">
    <tr>
    <td width="293" align="center" valign="middle">[img]/images/collection_images/banner_hadlens_title.jpg[/img]</td>
    </tr>
    <tr>
    <td height="97" align="center" valign="middle">

    <font color="#FFFFFF"><font color="#FFCC99" size="6">

    </font>
    <font color="#FFCC99" size="6">Thank you
    </font></font></p>


    <font color="#FFFFFF"><font color="#FFCC99" size="6">for contacting us.
    </font></font></p>


    <font color="#FFFFFF"><font color="#FFCC99" size="4">We will be in touch
    </font></font></p>


    <font color="#FFFFFF" size="4"><font color="#FFCC99">with you very soon</font></font><font color="#FFCC99" size="4">...</font></p>


    </p></td>
    </tr>
    </table><?Php
    }
    ?>

  2. #2
    Innanzitutto quando inserisci del codice è bene sia postato in maniera corretta ovvero utilizzando i tag [ code] e [ php] (sensa spazio) rispettivamente per il codice HTML (o di altro genere) e quello PHP.

    Riguardo la domanda da te posta devi semplicemente verificare che quel dato input sia stato passato. Una checkbox che non è stata spuntata non viene inviata.

    Pertanto il codice PHP deve essere qualcosa di simile:

    Codice PHP:
    if (isset($_POST['autorizzo2'])) {
        
    //Codice da eseguire solo in presenza della spunta alla checkbox


Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.