I received a message that they could not register on my website and, analyzing each element one by one, I realize that what causes the error is the following:
<input type="checkbox" id="brand1" name="agree">
<label for="brand1"><span></span>He leído y acepto los Términos de uso y Política de Privacidad</label>
Ajax response from my custom messages in PHP
if (isset($_POST['DataForm'])) {
$first_name = $_POST['first_name'];
$agree = $_POST['agree'];
if (empty($_POST['first_name'])) {
echo json_encode(['status'=> false, 'message'=>"<strong>Por favor, ingresé su nombre.</strong>"]);
exit;
}
if (empty($_POST['agree'])){
echo json_encode(['status'=> false, 'message'=>"<strong>Debes aceptar los terminos de uso/condiciones, politica de privacidad para continuar.</strong>"]);
exit;
}
}
I have to comment the following:
//$agree = $_POST['agree'];
For the form submission to work, it worked fine before, when the user did not select accept, ajax issued the following message:
You must accept the terms of use/conditions, privacy policy to continue
Because this happens, PHP in its new version no longer detects the:
<input type="checkbox" id="brand1" name="agree">
In this way:
$agree = $_POST['agree'];
In the meantime, with a solution add the following message:
By registering you agree to the terms of use and privacy policy
A
<input type="checkbox">
is only sent if it is selected, so when you try to fetch it with$agree = $_POST['agree'];
you are referencing a non-existent element.To illustrate what I am saying, I have set up an example:
Using the browser's developer tools, in the Network tab when you click on
<input type="submit">
a call is launched with the content of the<form>
. If thecheckbox
is not selected, nothing appears, since nothing is sent over it<input>
, but having it selected should look something like this:What I'm getting at is that it
$_POST['agree']
may or may not exist when we try to fetch its value on the server after POST , so the most appropriate way to handle it would be something like: