Problema form

surapazzo

Utente Attivo
10 Dic 2013
63
0
0
Buongiorno ho un problema con un form il mio codice è questo
Codice:
unction Modulo() {
    // Variabili associate ai campi del modulo
    var nome = document.getElementById("nome").value;
    var cognome = document.getElementById("cognome").value;
    var username = document.getElementById("username").value;
    var password = document.getElementById("password").value;
    var conferma = document.getElementById("conferma").value;
    var nascita = document.getElementById("nascita").value;
    var citta = document.getElementById("citta").options[document.getElementById("citta").selectedIndex].value;
    var indirizzo = document.getElementById("indirizzo").value;
    var telefono = document.getElementById("telefono").value;
    var email = document.getElementById("email").value;
  //  var homepage = document.modulo.homepage.value;
    var firma = document.getElementById("firma").value;
 
    // Espressione regolare dell'email
    var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
      
    //Effettua il controllo sul campo NOME
    if ((nome == "") || (nome == "undefined")) {
       alert("Il campo Nome è obbligatorio.");
        document.getElementById("nome").focus();
        return false;
    }
    //Effettua il controllo sul campo COGNOME
    else if ((cognome == "") || (cognome == "undefined")) {
        alert("Il campo Cognome è obbligatorio.");
        document.getElementById("cognome").focus();
        return false;
    }
    //Effettua il controllo sul campo NICKNAME
    else if ((username == "") || (username == "undefined")) {
        alert("Il campo Username è obbligatorio.");
        document.getElementById("username").focus();
        return false;
    }
    //Effettua il controllo sul campo PASSWORD
    else if ((password == "") || (password == "undefined")) {
        alert("Il campo Password è obbligatorio.");
        document.getElementById("password").focus();
        return false;
    }
    //Effettua il controllo sul campo CONFERMA PASSWORD
    else if ((conferma == "") || (conferma == "undefined")) {
        alert("Il campo Conferma password è obbligatorio.");
        document.getElementById("conferma").focus();
        return false;
    }
    //Verifica l'uguaglianza tra i campi PASSWORD e CONFERMA PASSWORD
    else if (password != conferma) {
        alert("La password confermata è diversa da quella scelta, controllare.");
        document.getElementById("conferma").value = "";
        document.getElementById("conferma").focus();
        return false;
    }
    //Effettua il controllo sul campo DATA DI NASCITA
    else if (document.getElementById("nascita").value.substring(2,3) != "/" ||
             document.getElementById("nascita").value.substring(5,6) != "/" ||
             isNaN(document.getElementById("nascita").value.substring(0,2)) ||
             isNaN(document.getElementById("nascita").value.substring(3,5)) ||
             isNaN(document.getElementById("nascita").value.substring(6,10))) {
         
        alert("Inserire nascita in formato gg/mm/aaaa");
        document.getElementById("nascita").value = "";
        document.getElementById("nascita").focus();
        return false;
    }
    else if (document.getElementById("nascita").value.substring(0,2) > 31) {
        alert("Impossibile utilizzare un valore superiore a 31 per i giorni");
        document.getElementById("nascita").select();
        return false;
    }
    else if (document.getElementById("nascita").value.substring(3,5) > 12) {
        alert("Impossibile utilizzare un valore superiore a 12 per i mesi");
        document.getElementById("nascita").value = "";
        document.getElementById("nascita").focus();
        return false;
    }
    else if (document.getElementById("nascita").value.substring(6,10) < 1900) {
        alert("Impossibile utilizzare un valore inferiore a 1900 per l'anno");
        document.getElementById("nascita").value = "";
        document.getElementById("nascita").focus();
        return false;
    }
    //Effettua il controllo sul campo CITTA'
    else if ((citta == "") || (citta == "undefined")) {
        alert("Il campo Città è obbligatorio.");
        document.getElementById("citta").focus();
        return false;
    }
    //Effettua il controllo sul campo INDIRIZZO
    else if ((indirizzo == "") || (indirizzo == "undefined")) {
        alert("Il campo Indirizzo è obbligatorio.");
        document.getElementById("indirizzo").focus();
        return false;
    }
    //Effettua il controllo sul campo TELEFONO
    else if ((isNaN(telefono)) || (telefono == "") || (telefono == "undefined")) {
        alert("Il campo Telefono è numerico ed obbligatorio.");
        document.getElementById("telefono").value = "";
        document.getElementById("telefono").focus();
        return false;
    }
    else if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
        alert("Inserire un indirizzo email corretto.");
        document.getElementById("email").select();
        return false;
    }
   
   
    //Effettua il controllo sul campo FIRMA
    else if ((firma == "") || (firma == "undefined") || (firma.indexOf("Inserisci qui il tuo slogan!") != (-1))) {
        alert("Il campo Firma è obbligatorio e non si può inserire la scritta predefinita.");
        document.getElementById("firma").focus();
        return false;
    }
    //INVIA IL MODULO
    
    else {
        document.modulo.action = "profile.php";
        document.modulo.submit();
    }
}
//-->




L'ho preso da un sito ma l'ultima parte non è adatta per il mio programma, come faccio ad inviare il form al mio database?
Grazie
 
Ciao, modifichi l'action del form
Codice:
document.modulo.action = "tuapagina.php";
con il nome della tua pagina php che elaborerà la richiesta
 
Non può non prenderlo
HTML:
<script>
    function Modulo() {
        document.modulo.action = "tuapagina.php";
        document.modulo.submit();
    }
</script>

<form name="modulo" method="post">
    <input type="text" name="prova"/>
    <input type="button" name="invia" value="Invia" onclick="Modulo()"/>
</form>
forse hai qualche errore nel form
 
Non può non prenderlo
HTML:
<script>
    function Modulo() {
        document.modulo.action = "tuapagina.php";
        document.modulo.submit();
    }
</script>

<form name="modulo" method="post">
    <input type="text" name="prova"/>
    <input type="button" name="invia" value="Invia" onclick="Modulo()"/>
</form>
forse hai qualche errore nel form

A meno che se sono in due cartelle separate devo dargli il path su action?
Perchè per il resto è uguale a quello che mi hai scritto e non capisco perchè mi dica che
document.modulo undefined:confused:
 
si

Sicuro di avergli dato name "modulo" e non "Modulo" o "moDulo" o "modulO" ?

Il problema è che il path secondo me non lo prende...
Se io ho il mio file con gli script in una cartella js che è allo stesso livello del file dove devo reindirizzare allora il path sarà cosi giusto?
../profile.php
giusto?
 

Discussioni simili