1
I have a modal that registers some information, and I need the error message (the one in bold) to appear only when the user forgets to fill in information such as identification, box type and status.
<div class="modal fade" id="CadastrarColmeia" tabindex="-1" role="dialog" aria-labelledby="CadastrarColmeia" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Cadastrar Colmeia</h5>
<img src = "img/colmeia.png" style="width: 50px">
</div>
<div style="margin: 5px;" id="MsgCadastroErroColmeia" class="alert alert-danger hide" role="alert">
Preencha os campos requeridos!
</div>
<div class="modal-body">
<form method="post" action="api/cadastrarColmeia.php">
<div class="form-row">
<div class="form-group col-md-6" >
<label for="inputCod">Identificação</label>
<input name="identificacao_colmeia" type="text" class="form-control" id="inputCod" placeholder="Identificação">
</div>
<div class="form-group col-md-6" >
<label for="inputCod">Data de alojamento</label>
<input name="alojamento_colmeia" type="date" class="form-control" id="inputAlojamento" placeholder="Data">
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label>Tipo de caixa</label>
<select name="tipo_caixa_colmeia" id="tipo_caixa_colmeia" class="form-control" required>
<option selected disabled="">Tipo de caixa</option>
<?php
require_once "api/conexao.php";
try {
$prepared = $conexao_pdo->prepare("select * from tipo_caixa");
$prepared->execute();
if ($result = $prepared->fetchAll()) {
for ($i=0; $i < sizeof($result); $i++) {
echo "<option value='". $result[$i]["cod"] ."'>". $result[$i]["tipo"] ."</option>";
}
} else {
echo "<option></option>";
}
} catch (PDOException $e) {
echo "<option></option>";
}
?>
</select>
</div>
<div class="form-group col-md-6">
<label for="inputEspecieAbelha">Espécie das Abelhas</label>
<input name="especieabelha_colmeia" type="text" class="form-control" id="inputEspecieAbelha" placeholder="Espécie das Abelhas">
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label for="inputAddress" style="line-height: 1.5; margin-left: 185px; vertical-align: middle;">Coordenadas</label>
<input name="latitude_colmeia" type="text" class="form-control" id="inputAddress" placeholder="Latitude">
</div>
<div class="form-group col-md-6">
<label for="inputAddress2">.</label>
<input name="longitude_colmeia" type="text" class="form-control" id="inputAddress2" placeholder="Longitude">
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6" >
<label for="inputQuadros">Nº de quadros</label>
<input name="numQuadros_colmeia" type="number" class="form-control" id="inputQuadros" placeholder="Número de quadros ">
</div>
<div class="form-group col-md-6" >
<label for="inputQuadrosCria">Nº de quadros com cria</label>
<input name="numQuadrosCria_colmeia" type="text" class="form-control" id="inputQuadrosCria" placeholder="Quadros com cria">
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6" >
<label for="inputPotencialProdutivo">Potencial produtivo (kg)</label>
<input name="potencialProdutivo_colmeia" type="number" class="form-control" id="inputPotencialProdutivo" placeholder="Potencial Produtivo">
</div>
<div class="form-group col-md-6" >
<label for="inputStatus">Status</label>
<select name="status_colmeia" id="status_colmeia" class="form-control" required>
<option selected disabled="">Status</option>
<?php
require_once "api/conexao.php";
try {
$prepared = $conexao_pdo->prepare("select * from status");
$prepared->execute();
if ($result = $prepared->fetchAll()) {
for ($i=0; $i < sizeof($result); $i++) {
echo "<option value='". $result[$i]["cod"] ."'>". $result[$i]["desc"] ."</option>";
}
} else {
echo "<option></option>";
}
} catch (PDOException $e) {
echo "<option></option>";
}
?>
</select>
</div>
</div>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">Observações</span>
</div>
<textarea name="observacoes_colmeia" class="form-control" aria-label="With textarea"></textarea>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancelar</button>
<button id="buttoneviarcolmeia" onclick="ErroColmeia()" type="submit" class="btn btn-primary">Salvar</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
But what would be "didn’t work out the way I wanted"? And how would you like it to stay?
– hugocsl
I just want a reminder to appear with "Fill in this field"
– Nathi