Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 11
  1. #1

    Form in php: campi obbligatori

    NON funziona il codice del campo obbligatorio del form in php che ho creato GRAZIE a voi,.

    Ho fatto una prova, ho saltato tutte le stringhe (nome, cognome, email) e ho scritto solo nel campo del website e mi è arrivata l'email lo stesso.

    il codice in php è questo:

    $first = $_POST['first']; // required
    $last = $_POST['last']; // required
    $address = $_POST['address']; // not required
    $number = $_POST['number']; // not required
    $city = $_POST['city']; // not required
    $state = $_POST['state']; // not required
    $email = $_POST['email']; // required
    $website = $_POST['website']; // required
    $request = $_POST['request']; // required


    Dov'è l'errore secondo voi ??

  2. #2
    Utente di HTML.it L'avatar di telegio
    Registrato dal
    Sep 2001
    Messaggi
    2,592
    ..DOVE è SCRITTO che sono obbligatori?

  3. #3
    Utente di HTML.it L'avatar di bstefano79
    Registrato dal
    Feb 2004
    Messaggi
    2,520
    telegio mi meraviglio di te, non leggi???
    // not required
    // required



    ok ok scusate

  4. #4
    Utente di HTML.it L'avatar di telegio
    Registrato dal
    Sep 2001
    Messaggi
    2,592
    Originariamente inviato da bstefano79
    telegio mi meraviglio di te, non leggi???
    // not required
    // required



    ok ok scusate
    [OT MODE]

    [/OT MODE]

  5. #5
    Originariamente inviato da bstefano79
    telegio mi meraviglio di te, non leggi???
    // not required
    // required


    ok ok scusate
    si ma purtroppo NON mi funziona..... io ieri ho compilato SOLO nella stringa del website, e l'email mi è arrivata lo stesso... invece mi doveva dare errore e dirmi che il nome, cognome, email, e la domanda sono obbligatori...

    Help me, please...

  6. #6
    Utente di HTML.it L'avatar di bstefano79
    Registrato dal
    Feb 2004
    Messaggi
    2,520
    ok usciamo dalla fase ot, e scusa se l'ho presa un po' sul ridere......
    cmq una riga o parte della riga con prefisso // sta a significare che quello è un commento, ovvero una sequenza di caratteri che verrà ignorata quando si vanno a creare le istruzioni macchina. In pratica
    // not required
    // required
    non sta a significare nulla, solo un commento per vedeer a colpo d'occhio senza leggere il codice quale campo è obbligatorio.... Ma il codice però va scritto altrimenti il pc non lo capisce

  7. #7
    ho capito, e una riga di esempio di obbligatorio sul mio caso ?

    if (trim($nome)=="") {
    print "Tutti i campi del form sono obbligatori...Torna indietro e inserisci il tuo nome!! Grazie!!";
    }

    questo potrebbe andare bene per quello che cerco ?

  8. #8
    Utente di HTML.it
    Registrato dal
    Jul 2006
    Messaggi
    161
    sì, oppure più elegantemente
    Codice PHP:
    if(empty($name)) {
       ...

    visto che hai più cambi obbligatori, sarebbe meglio non stampare tutto, ma concatenare i vari possibili errori in una variabile e stampare tutto alla fine

  9. #9
    Sono andata in tilt, aiutatemi, a mettere i campi obbligatori, che sono first,last,email,website, autorizzo e request.

    Grazie.

    Mi da questo errore:

    Parse error: syntax error, unexpected T_BOOLEAN_AND, expecting ',' or ')' in D:\Inetpub\webs\miosito\send_info.php on line 33

    VI PREGO ditemi dove ho sbagliato (ho tolto i miei dati sensibili):


    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
    }
    ?>

  10. #10
    Utente di HTML.it
    Registrato dal
    Jul 2006
    Messaggi
    161
    Mi da questo errore:
    Parse error: syntax error, unexpected T_BOOLEAN_AND, expecting ',' or ')' in D:\Inetpub\webs\miosito\send_info.php on line 33
    il codice postato così non è che aiuti...
    l'errore mi pare abbastanza chiaro, hai saltato qualche parentesi o virgola

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 © 2025 vBulletin Solutions, Inc. All rights reserved.