Visualizzazione dei risultati da 1 a 4 su 4

Discussione: Errore nel form PHP

  1. #1

    Errore nel form PHP

    Ho questo codice:

    codice:
    html>
    <body>
    
    
    
    
    <?php
    if ($_POST['submit']) {
    $required_fields = explode(",", $_POST['required']);
    
    $error = 0;
    
    foreach($required_fields as $fieldname) {
    if ($_POST[$fieldname] == "") {
    $error++;
    }
    }
    
    if ($error == 0) {
    if (strstr($_POST['email'], "@") and strstr($_POST['email'], ".")) {
    
    mail("youremail@your.com" , "Message from Web Form", $_POST['message'], "From: $_POST[name] <$_POST[email]>");
    
    print "<html><body>Thank you for submitting your comments $_POST[name]!</body></html>";
    exit;
    
    } else { 
    $errormessage = "The email address you entered does not appear to be valid
    ";
    }
    
    } else {
    $errormessage = "[b]You have left some required fields in the form blank! Please fill in the form completely.";
    }
    }
    ?>
    
    <?=$errormessage?>
    
    
    
    <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
    <table width="500" border="0" cellpadding="5" cellspacing="0">
    <tr><td>Your name:</td><td><input type="text" name="name" value="<?=$_POST['name']?>"></td></tr>
    <tr><td>Your email:</td><td><input type="text" name="email" value="<?=$_POST['email']?>"><td><tr>
    <tr><td>Your message:</td><td><textarea name="message"><?=$_POST['message']?></textarea></td></tr></table>
    <input type="hidden" name="required" value="name,email,message">
    <input type="submit" name="submit" value="submit">
    
    </body></html>
    ma mi da questo errore subito:

    Notice: Undefined index: submit in c:\inetpub\wwwroot\php\mail.php on line 6

    Notice: Undefined variable: errormessage in c:\inetpub\wwwroot\php\mail.php on line 35

    e lo stesso all interno degli input come value.
    Dove sbaglio?

  2. #2
    ti manca un "<" ad <html>
    GdR Online - http://lenar.it/
    Yesterday is history. Tomorrow is mystery.
    Today is a gift. That's why it's called the present

  3. #3
    il < mancante penso sia solo un errore di copia/incolla nel post... piuttosto, submit è da prelevare così:

    Codice PHP:
    $submit = isset ($_POST['submit']) ? $_POST['submit'] : '';
    if (
    $submit) {
    // eccetera 
    idem per le altre variabili che prelevi da form
    Sotto la panza la mazza avanza.

  4. #4
    Grazie adesso funziona.

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.