I am working with PHP. I have a form for submitting applications. When a form is entered, the system sends an email with PHPMailer with the request information, all of this works fine. But entering a request notice a detail that so far I have not been able to solve. When I press SUBMIT to create a request, the system takes a few seconds to display the message that the record was entered, and in those seconds of waiting if I press submit again, the system creates new requests that are stored in the database and also sends mail for each time you press SEND. I would like someone to tell me how to control and prevent a user from sending the same request several times.
I share my code:
//MY FORM//
Request Internship <div class="panel-body">
<div class="col-md-12">
<form method="post" action="ingresar_pasantia.php" class="clearfix">
<div class="form-group">
<div class="input-group">
<span class="input-group-addon">
<i class="glyphicon glyphicon-user"></i>
</span>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-5">
<div class="input-group">
<span class="input-group-addon">
<i class="glyphicon glyphicon-th-list"></i>
</span>
<input type="text" name="nombre_docente" placeholder="Nombres">>
</div>
</div>
<div class="col-md-5">
<div class="input-group">
<span class="input-group-addon">
<i class="glyphicon glyphicon-th-list"></i>
</span>
<input type="text" name="apellido_docente" placeholder="Apellidos">
</div>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-4">
<div class="input-group">
<span class="input-group-addon">
<i class="glyphicon glyphicon-th-list"></i>
</span>
<input type="text" name="rut" placeholder="Rut" maxlength="10">
</div>
</div>
<div class="col-md-5">
<div class="input-group">
<span class="input-group-addon">
<i class="glyphicon glyphicon-envelope"></i>
</span>
<input type="email" name="email" placeholder="E-Mail">
</div>
</div>
</div>
</div>
<button type="submit" name="ingresar_pasantia">Enviar</button>
<a href="pasantia.php" class="btn btn-primary">Mis Solicitudes</a>
</form>
</div>
</div>
</div>
</div>
// SAVE RECORD IN DATABASE //
if(isset($_POST['ingresar_pasantia']))
{
$req_fields = array('nombre_docente','apellido_docente','rut','email');
validate_fields($req_fields);
if(empty($errors))
{
$nombre_docente = remove_junk($db->escape($_POST['nombre_docente']));
$apellido_docente = remove_junk($db->escape($_POST['apellido_docente']));
$rut = remove_junk($db->escape($_POST['rut']));
$email = remove_junk($db->escape($_POST['email']));
$query = "INSERT INTO pasantia (";
$query .=" nombre_docente, apellido_docente, rut, email";
$query .=") VALUES (";
$query .=" '{$nombre_docente}','{$apellido_docente}','{$rut}','{$email}'";
$query .=")";
$query .=" ON DUPLICATE KEY UPDATE nombre_docente='{$nombre_docente}'";
if($db->query($query))
{
$session->msg('s',"Solicitud ingresada exitosamente. ");
redirect('ingresar.php', false);
unlink($path);
}
else
{
$session->msg('d',' Lo siento, registro falló.');
redirect('prod.php', false);
}
}
else
{
$session->msg("d", $errors);
redirect('ingresar.php',false);
}
}
If the problem is with disabled , I don't usually use it, this attribute completely disables the element, it pretends it doesn't exist, in this case we are assigning it to a button in a form, which makes it not fulfill its function and also that of the previous elements, in this case the information inputs, this would work if we did it with Ajax in beforesend . NOW WE MAKE THE MODIFICATION FROM CSS, WE ADD A CLASS WHEN DOING THE SUBMIT OF THE FORM, DISABLING THE CURSORS:
TELL ME IF IT'S GOOD.
I solved it with the following function: