• User

    Problema con form

    Salve ragazzi! Nel mio sito ho inserito un form il quale prima dell'invio richiede il calcolo di una formula per prevenire lo spam. Ebbene tutto funziona a dovere solo che con internet explorer ricevo 2 errori durante l'invio eccoli:

    Linea: 65
    Carattere: 1
    Errore: 'required' non è definito 
    Codice: 0
    URL: http://www.winrevolution.com/Richieste/form.php?done=1
    

    Linea: 32
    Carattere: 15
    Errore: Previsto ';'
    Codice: 0
    URL: http://www.winrevolution.com/Richieste/form.php?done=1

    
    

    <form name="fcform2" method="post" action="process_form.php" onsubmit="return validate.check()">
    <div id="fcf2">
    <h3>Contattami</h3>
    <p>I campi contrassegnati con <em>*</em> sono obbligatori.</p>

    <div class="r">
    <label for="fullname" class="req">Nome: <em>*</em></label>
    <span class="f">
    <input type="text" name="fullname" size="40" id="fullname" onBlur="trim('fullname')">
    </span>
    </div>

    <div class="r">
    <label for="email" class="req">Indirizzo email: <em>*</em></label>
    <span class="f">
    <input type="text" name="email" size="40" id="email" onBlur="trim('email')">
    </span>
    </div>

    <div class="r">
    <label for="comments" class="req">Commento: <em>*</em></label>
    <span class="f">
    <textarea cols="30" rows="8" name="comments" id="comments" onBlur="trim('comments')"></textarea>
    </span>
    </div>

    <div class="r">
    <label for="quest" class="req"><?php echo $question; ?> <em>*</em></label>
    <span class="f">
    <input type="text" name="answer_out" size="6" id="answer_out" onBlur="trim('answer_out')">  

    Prevenzione spam.

    </span>
    </div>

    <div class="sp"> </div>

    <?php
    if(isset($_GET['done'])) {
    echo '<div align="center" style="color:red;font-weight:bold">'.$confirmation_message.'</div><br />';
    }
    ?>
    <p align="center">
    <input type="submit" value="Invia">
    <br />
    </p>
    </div>

        <input type="hidden" name="answer_p" value="<?php echo $answer_pass; ?>">
        <input type="hidden" name="enc" value="<?php echo $enc; ?>">
    

    </form>


  • Super User

    credo sia un problema di javascript, quindi dovresti postare anche il codice javascript...


  • User

    Ecco il codice javascript

    function $$(id) {
    try {
    var tmp = document.getElementById(id).value;
    }
    catch(e) {
    alert("Field " + id + " does not exist!\nvalidation is configured on a field with no ID");
    return false;
    }
    if(tmp == "") {
    alert("Field " + id + " cannot be empty");
    return false;
    }
    return tmp;
    }
    
    var required = {
    field : [],
    add : function(name, type) {
    this.field[this.field.length] = [name,type];
    },
    out : function() {
    return this.field;
    }
    }
    
    var validate = {
    
    check : function() {
    var tmp;
    // loop all required fields
    for(var i=0; i<required.field.length; i++) {
    // check the form field exists
    this.tmp = $$(required.field*[0]);
    if(this.tmp) {
    if(this.checkit(required.field*[0],required.field*[1])) {
    // validated okay
    } else {
    alert("Field "+required.field*[0]+" not valid\n");
    document.getElementById(required.field*[0]).focus();
    return false;
    }
    } else {
    try {
    document.getElementById(required.field*[0]).focus();
    } catch(e) { }
    return false;
    }
    } // for
    return true;
    },
    
    checkit : function(value,type) {
    exp : '';
    switch(type) {
    
    case "NOT_EMPTY":
    if(this.trim($$(value)).length < 1) { return false; } else { return true; }
    break;
    
    case "ALPHA":
    exp = /^[A-Za-z]+$/;
    if($$(value).match(exp)==null) { return false; } else { return true; }
    break;
    
    case "ALPHASPACE":
    exp = /^[A-Za-z ]+$/;
    if($$(value).match(exp)==null) { return false; } else { return true; }
    break;
    
    case "NUMERIC":
    exp = /^[0-9]+$/;
    if($$(value).match(exp)==null) { return false; } else { return true; }
    break;
    
    case "NUMERICPLUS":
    exp = /(^-*\d+$)|(^-*\d+\.\d+$)/;
    if($$(value).match(exp)==null) { return false; } else { return true; }
    break;
    
    case "ALPHANUM":
    exp = /^[a-zA-Z0-9]+$/;
    if($$(value).match(exp)==null) { return false; } else { return true; }
    break;
    
    case "ALPHANUMSPACE":
    exp = /^[a-zA-Z0-9 ]+$/;
    if($$(value).match(exp)==null) { return false; } else { return true; }
    break;
    
    case "EMAIL":
    exp = /^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
    if($$(value).match(exp)==null) { return false; } else { return true; }
    break;
    
    case "YYYYMMDD":
    exp = /^(19|20)[0-9][0-9][- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$/;
    if($$(value).match(exp)==null) { return false; } else { return true; }
    break;
    
    case "DDMMYYYY":
    exp = /^(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)[0-9][0-9]$/;
    if($$(value).match(exp)==null) { return false; } else { return true; }
    break;
    
    case "MMDDYYYY":
    exp = /^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)[0-9][0-9]$/;
    if($$(value).match(exp)==null) { return false; } else { return true; }
    break;
    
    default:
    exp = new RegExp(type);
    if($$(value).match(exp)==null) { return false; } else { return true; }
    } // switch
    },
    trim : function(s) {
    return s.replace(/^\s+/, '').replace(/\s+$/, '');
    }
    
    }
    function $val(id) {
    return document.getElementById(id);
    }
    function trim(id) {
    $val(id).value = $val(id).value.replace(/^\s+/, '').replace(/\s+$/, '');
    }