Good afternoon,
I think the title is badly expressed, I'll edit it when I think of a more precise question.
Basically I explain my problem:
I have a web page with an information request form. The action of the form is redirected to the same page where this code is:
require_once("../CBSPlatform/assets/classes/class.sistema.php");
require_once("../CBSPlatform/assets/classes/class.solicitudinfo.php");
require_once("../CBSPlatform/assets/functions.php");
require_once("assets/core.php");
$solicitud = new SolicitudInfo;
if (isset($_POST['solicitudinfo'])) {
$centro = secure($_POST['centro']);
$curso = secure($_POST['curso']);
$nombre = ucwords(strtolower(secure($_POST['nombre'])));
$apellido = ucwords(strtolower(secure($_POST['apellidos'])));
$fechanacimiento = secure($_POST['fechanacimiento']);
$poblacion = ucwords(strtolower(secure($_POST['pueblo'])));
$codpostal = secure($_POST['codpostal']);
$nombretutor = ucwords(strtolower(secure($_POST['nombretutor'])));
$apellidostutor = ucwords(strtolower(secure($_POST['apellidostutor'])));
$email = strtolower(secure($_POST['email']));
$movil = secure($_POST['movil']);
$conocen = secure($_POST['conocen']);
$observaciones = ucfirst(strtolower(secure($_POST['observaciones'])));
$dia = date("d") . "/" . date("m") . "/" . date("Y");
$hora = date("G") . ":" . date("i") . ":" . date("s");
$solicitud->addSolicitud($dia, $hora, $centro, $curso, $nombre, $apellido, $fechanacimiento, $poblacion, $codpostal, $nombretutor, $apellidostutor, $email, $movil, $conocen, $observaciones);
if($solicitud == true) {
echo "ggez";
} else {
echo "";
}
$_POST = array();
};
The class.solicitudinfo has this code:
public function addSolicitud($dia, $hora, $centro, $curso, $nombre, $apellido, $fechanacimiento, $poblacion, $codpostal, $nombretutor, $apellidostutor, $email, $movil, $conocen, $observaciones) {
$sql = $this->db->prepare("INSERT INTO webla_solicitudinfo (DiaSolicitud, HoraSolicitud, Centro, CursoEscolar, Nombre, Apellidos, FechaNacimiento,
Poblacion, CodPostal, NombreTutor, ApellidosTutor, EmailContacto, MovilContacto, ComoConocen, Observaciones) VALUES (:dia, :hora, :centro, :cursoescolar,
:nombre, :apellidos, :fechanacimiento, :poblacion, :codpostal, :nombretutor, :apellidostutor, :emailcontacto, :movilcontacto, :comoconocen, :observaciones)");
$sql->execute(array(':dia'=>$dia,':hora'=>$hora,':centro'=>$centro,':cursoescolar'=>$curso,':nombre'=>$nombre,':apellidos'=>$apellido,
':fechanacimiento'=>$fechanacimiento,':poblacion'=>$poblacion,':codpostal'=>$codpostal,':nombretutor'=>$nombretutor,
':apellidostutor'=>$apellidostutor,':emailcontacto'=>$email,':movilcontacto'=>$movil,':comoconocen'=>$conocen,
':observaciones'=>$observaciones));
return true;
}
I want to change everything and do it through AJAX, so that when they send the form automatically go to the database and if it has been inserted correctly, I will return an alert that I will do with the sweetalert plugin confirming that the request has been made correctly.
The problem with what I have done so far (It works correctly) is that if you reload the page once you have sent the form, it is sent again since the data of $ _POST is not deleted. Besides that if someone explained to me how to do it with ajax, I could understand the use of AJAX and be able to use it in the other forms and applications I am doing.
Could someone give me a cable and explain how to do it or tell me a page that explains how to do it?
Greetings.