Ver Mensaje Individual
  #3 (permalink)  
Antiguo 29/07/2014, 10:42
crash_rpm
 
Fecha de Ingreso: agosto-2012
Ubicación: Almeria
Mensajes: 50
Antigüedad: 11 años, 8 meses
Puntos: 0
Respuesta: Funcion para validar formulario en Firefox no funciona

Pensaba que era problema de alguna opcion del form que no servia en Firefox.
Os pongo mas codigo:

Código:
<form enctype="multipart/form-data" method="POST" action="insertar_bd.php" name="formulario" class="formulario" onsubmit="return validarEvento('evento');">

<?php
        if($tipo == "eventos")
       	{?>
.
.Varios campos del formulario
.
<div class="error" id="error" style="width:600px">

</div>

<div class="error" id="error" style="width:600px">

		</div>
        <div id="loadingFiesta" style='display:none;'> <div style='text-align:center;padding-bottom: 2px;color:grey;font-weight:bold;'> Subiendo imágenes al servidor, espere un momento</div> <div style='text-align:center;'> <img src='img/diseno/generales/loading2.gif' alt='loading' style='margin-top:2px;text-align:center;' /></div></div>
        <input type="hidden" value="eventos" id="tipo" name="tipo" />
        <input type="submit" value="Enviar" id="bEvento" class="button"  />

        <?php
	}
    else{

    }?>

    <?php
    //Por si venimos de un error
    if(isset($_POST['error']))
                echo "<br/><br/><p style='color:brown'> $error; </p>";

            ?>
        </form>
La funcion de validarEvento es esta:
Código:
function validarEvento(tipo)
{
    var valido = true;
    var error = "";

    if(tipo != 'fotos')
    {
        if(document.formulario.titulo.value ==  '')
        {
            error = error + "* Error, introduzca el nombre o descripción del evento <br/>";
            valido =  false;
        }


	    //validar fecha
	    var f = new Date()
	    var año = f.getFullYear();
	    var mes = f.getMonth()+1;
	    var dia = f.getDate();
	    if(document.formulario.dia.value == '0' || document.formulario.año.value == '0' || document.formulario.mes.value == '0')
	    {
	        error = error + "* Error, introduzca una fecha correcta. <br/>";
	        valido =  false;
	    }
	    else if(tipo == 'evento')
	    {
	        var aux = document.formulario;
	        aceptado = true;
	        if(aux.año.value > año)
	            aceptado = false;
	        else if(aux.año.value == año)
	        {
	            if(aux.mes.value > mes)
	                aceptado = false;
	            else if(aux.mes.value == mes)
	            {
	                if(aux.dia.value > dia)
	                    aceptado = false;
	            }
	        }
	        if(aceptado == false)
	        {
	            error = error + "* Fecha errónea. Si quiere insertar un evento futuro vaya a la sección de Próximos Eventos, en caso contrario introduzca una fecha anterior  a la actual.. <br/>";
	            valido =  false;
	        }
	    }
	    else
	    {
	        var aux = document.formulario;
	        aceptado = true;
	        if(aux.año.value < año)
	            aceptado = false;
	        else if(aux.año.value == año)
	        {
	            if(aux.mes.value < mes)
	                aceptado = false;
	            else if(aux.mes.value == mes)
	            {
	                if(aux.dia.value < dia)
	                    aceptado = false;
	            }
	        }
	        if(aceptado == false)
	        {
	            error = error + "* Error, la fecha introducida ya ha pasado. <br/>";
	            valido =  false;
	        }
	    }
	}


    if(document.formulario.imagen.value == '')
    {
        error = error + "* Error, debe introducir alguna imagen <br/>";
        valido =  false;
    }




    if(document.getElementById("tipo2") != 'prox' && document.getElementById("lbl_imagen2") != null)
    {
        //Verifica si hay 2 imagenes con el mismo nombre
        if(document.getElementById("lbl_imagen2").style.display == "block"  && document.getElementById("imagen2").value != "")
        {
            var tam = 2;
             for(tam = 2; document.getElementById("lbl_imagen"+tam).style.display == "block" && document.getElementById("imagen"+tam).value != "";tam++);


            if(document.formulario.imagen.value == document.getElementById("imagen2").value)
            {
                error = error + "* Error al insertar imágenes, hay 2  con el mismo nombre <br/>";
                valido =  false;
                flag = true;
            }
            else
            {
                var flag = false;
                for(i=2;i<tam && flag == false;i++)
                {
                    if(document.formulario.imagen.value == document.getElementById("imagen"+i).value)
                    {
                        error = error + "* Error al insertar imágenes, hay 2 con el mismo nombre <br/>";
                        valido =  false;
                        flag = true;
                    }
                    for(j=i+1;j<=tam && flag == false;j++)
                    {


                        if(document.formulario.imagen.value == document.getElementById("imagen"+j).value)
                        {
                            error = error + "* Error al insertar imágenes, hay 2  con el mismo nombre <br/>";
                            valido =  false;
                            flag = true
                        }
                        else if(document.getElementById("imagen"+i).value == document.getElementById("imagen"+j).value)
                        {
                            error = error + "* Error al insertar imágenes, hay 2 con el mismo nombre <br/>";
                            valido =  false;
                            flag = true
                        }
                    }
                }
            }
        }
    }