3
How do I place this mandatory field:
<p><h5><strong>Estado</strong></h5>
<p> <input type="radio" name="Estado" value="Concluído">Concluído
3
How do I place this mandatory field:
<p><h5><strong>Estado</strong></h5>
<p> <input type="radio" name="Estado" value="Concluído">Concluído
1
Just add the required attribute to the input tag. It would look something like:
<input type="radio" name="Estado" value="Concluído" required>Concluído
The safest is to do a validation in php itself. As the user can by Debugger simply delete the required.
Yes, it is a security issue to validate all fields both on the front and back. Validating the data on the front serves mainly for a better user experience, which will already know what filled wrong before sending the form.
0
You can do a check front-end with Javascript (the e.preventDefault();
will prevent the form from being sent):
document.querySelector("form").addEventListener("submit", (e)=>{
if(!document.querySelector("input[name='Estado']").checked){
alert("Marque o radio button");
e.preventDefault();
}
});
And do the check on back-end in PHP (most importantly!):
<?php
$Estado = $_POST['Estado'];
if(isset($Estado) && !empty($Estado)){
echo "Estado foi checado";
}else{
echo "Estado não foi checado";
}
?>
Browser other questions tagged php html mysql
You are not signed in. Login or sign up in order to post.
You should not only add the required input, but also do a validation in php for greater security. If you put what code you receive this post or get after sending the form. Maybe we can help you better.
– David Alves