Foros del Web » Programando para Internet » PHP »

ALERT con php

Estas en el tema de ALERT con php en el foro de PHP en Foros del Web. HOLA COMPAÑEROS, ANTES QUE NADA SALUDOS. ME GUSTARIA SABER SI ME PODRIAN AYUDAR LO QUE PASA ES QUE TENGO UN FORMULARIO EN EL CUAL VOY ...
  #1 (permalink)  
Antiguo 21/10/2008, 18:00
 
Fecha de Ingreso: septiembre-2008
Mensajes: 152
Antigüedad: 15 años, 7 meses
Puntos: 1
Exclamación ALERT con php

HOLA COMPAÑEROS, ANTES QUE NADA SALUDOS.

ME GUSTARIA SABER SI ME PODRIAN AYUDAR LO QUE PASA ES QUE TENGO UN FORMULARIO EN EL CUAL VOY A REGISTRAR A UN USUARIO Y TENGO CIERTOS CAMPOS OBLIGATORIOS (nombre,email...etc) Y LO QUE QUIERO HACER ES QUE CUANDO DETECTE QUE UN CAMPO ESTA VACIO ME MANDE UNA ALERTA EL PROBLEMA QUE TENGO ES QUE EL FORMULARIO SI DETECTA QUE ESTA VACIO ALGUN CAMPO PERO AL MANDAR LA ALERTA SE RECARGA LA PAGINA Y SE ME LIMPIAN LOS CAMPOS QUE YA ESTABAN LLENOS, HE ESTADO LEYENDO ALGO SOBRE AJAX PERO LA VERDAD NO LE ENTIENDO MUCHO OJALA ME PUEDAN AYUDAR

DE ANTEMANO GRACIAS
  #2 (permalink)  
Antiguo 21/10/2008, 18:07
Avatar de ElJavista
Colaborador
 
Fecha de Ingreso: marzo-2007
Ubicación: Lima Perú
Mensajes: 2.231
Antigüedad: 17 años, 1 mes
Puntos: 67
Respuesta: ALERT con php

A lo mejor no entiendes sobre ajax porque no sabes JavaScript. Bien, tienes unas alternativas. Ya que has enviado el formulario pues tienes los valores que se han enviado. Esos valores debes imprimirlos en el mismo form. Para eso debes enviar el formulario a la misma página para ser procesado. Si no valida correctamente se muestra otra vez el mismo formulario pero esta vez imprimes los valores en cada elemento del form. La cosa es de lo más simple.

Otra alternativa es que aprendas ajax, comienza aprendiendo algo de JavaScript y luego pasa a ajax, no es tan difícil.
  #3 (permalink)  
Antiguo 21/10/2008, 19:51
Avatar de jam1138
/** @package Moderador */
 
Fecha de Ingreso: julio-2004
Ubicación: sèveR led onieR lE
Mensajes: 9.368
Antigüedad: 19 años, 9 meses
Puntos: 102
Respuesta: ALERT con php

HOYGAN!! ia bieron el nuebo 120segundos???
http://www.forosdelweb.com/f74/120-m...grafia-634340/

kalvera85, leer en mayúsculas es realmente molesto. Cuida la manera en que colocas los temas; ahí como consejo no pedido :-/.

Un saludo

PD: Lee las FAQ. Hay una que intenta explicar la diferencia entre PHP y JavaScript. En resumen: no puedes hacer "alerts" con PHP, salvo imprimir JavaScript dinámicamente después de enviar la información... pero no deja de ser JavaScript. Supongo tu buscas un validador en JS, busca --por favor-- en aquel foro que hay muchos,. muchos, muchos temas igual al tuyo. Suerte
__________________
٩(͡๏̯͡๏)۶
» Cómo hacer preguntas de manera inteligente «

"100 años después, la revolución no es con armas, es intelectual y digital"
  #4 (permalink)  
Antiguo 21/10/2008, 21:57
 
Fecha de Ingreso: septiembre-2008
Mensajes: 350
Antigüedad: 15 años, 7 meses
Puntos: 31
Respuesta: ALERT con php

Source Code: http://www.tizag.com/javascriptT/javascriptform.php

Código HTML:
<script type='text/javascript'>

function formValidator(){
	// Make quick references to our fields
	var firstname = document.getElementById('firstname');
	var addr = document.getElementById('addr');
	var zip = document.getElementById('zip');
	var state = document.getElementById('state');
	var username = document.getElementById('username');
	var email = document.getElementById('email');
	
	// Check each input in the order that it appears in the form!
	if(isAlphabet(firstname, "Please enter only letters for your name")){
		if(isAlphanumeric(addr, "Numbers and Letters Only for Address")){
			if(isNumeric(zip, "Please enter a valid zip code")){
				if(madeSelection(state, "Please Choose a State")){
					if(lengthRestriction(username, 6, 8)){
						if(emailValidator(email, "Please enter a valid email address")){
							return true;
						}
					}
				}
			}
		}
	}
	
	
	return false;
	
}

function notEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return false;
	}
	return true;
}

function isNumeric(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphabet(elem, helperMsg){
	var alphaExp = /^[a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphanumeric(elem, helperMsg){
	var alphaExp = /^[0-9a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function lengthRestriction(elem, min, max){
	var uInput = elem.value;
	if(uInput.length >= min && uInput.length <= max){
		return true;
	}else{
		alert("Please enter between " +min+ " and " +max+ " characters");
		elem.focus();
		return false;
	}
}

function madeSelection(elem, helperMsg){
	if(elem.value == "Please Choose"){
		alert(helperMsg);
		elem.focus();
		return false;
	}else{
		return true;
	}
}

function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}
</script>

<form onsubmit='return formValidator()' >
First Name: <input type='text' id='firstname' /><br />
Address: <input type='text' id='addr' /><br />
Zip Code: <input type='text' id='zip' /><br />
State: <select id='state'>
	<option>Please Choose</option>
	<option>AL</option>
	<option>CA</option>
	<option>TX</option>
	<option>WI</option>
</select><br />
Username(6-8 characters): <input type='text' id='username' /><br />
Email: <input type='text' id='email' /><br />
<input type='submit' value='Check Form' />
</form> 
  #5 (permalink)  
Antiguo 23/10/2008, 14:23
 
Fecha de Ingreso: septiembre-2008
Mensajes: 152
Antigüedad: 15 años, 7 meses
Puntos: 1
Respuesta: ALERT con php

Disculpen por lo tardanza para responder este tema, solo les quiero agradecer por su ayuda y los consejos que me dieron gracias a los 3 no cabe duda que en este foro se encuentran personas con grandes conocimientos, gracias a uds he resulto mi problema

GRACIAS!!!!

Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 00:24.