0
I am trying to validate my form with bootstrapValidator, in PHP but the script does not run, but if I do an html file, the file runs.
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="utf-8">
<title>Cadastro de Vagas</title>
<body>
<?php include("masterpage.php") ?>
<div class="container">
<div class="row">
<section>
<div class="col-lg-8 col-lg-offset-2">
<div class="page-header">
<h2>Cadastro de vagas</h2>
</div>
<form id="form" method="post" class="form-horizontal">
<div class="form-group">
<label class="col-lg-3 control-label"> Cargo: </label>
<div class="col-lg-4">
<input type="text" class="form-control" name="Cargo" placeholder="Cargo" />
<span class="help-block" id="CargoMsg" />
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Descricao</label>
<div class="col-lg-5">
<input type="text" class="form-control" name="Descricao" placeholder="Descrição" />
<span class="help-block DescricaoMsg" />
</div>
</div>
<div class="form-group">
<label class="control-label" for="campoData"> Data final inscrição:</label>
<div class="input-group">
<span class="input-group-addon"></span>
<input type="text" name="data" id="data"/>
</div>
</div>
<div class="col-lg-9 col-lg-offset-3">
<button type="submit" class="btn btn-primary">Efetuar Cadastro</button>
<button type="reset" class="btn btn-danger">Limpar formulário</button>
</div>
</div>
</form>
</div>
</section>
<!-- :form -->
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
$('#form').bootstrapValidator({
message: 'This value is not valid',
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
Cargo: {
container: '#CargoMsg',
validators: {
notEmpty: {
message: 'Cargo é obrigatório e não pode ser vazio.'
},
stringLength: {
min: 3,
max: 50,
message: 'Cargo tem que ter mais de 3 letras e menos de 50.'
}
}
},
Descricao: {
container: '.DescricaoMsg',
validators: {
notEmpty: {
message: 'Descrição é obrigatória e não pode ser vazia.'
},
stringLength: {
min: 3,
max: 5000,
message: 'Descrição tem que ter mais de 3 letras e menos de 5000.'
}
}
}
}
});
});
</script>
</body>
Bootstrap js files are loaded into the page? copied them to the Xampp folder?
– gmsantos
They are and I also upload them to the masterpage to ensure, and are in the project folders within Xampp
– Alinehx
The address called in the browser is http://localhost/project or file:///file.php
– rray
the address is http://localhost:8080/project/view/cadastre
– Alinehx
If the loose file runs the syntax is OK. Is there any other element with
id="form"
on the page? If yes, it can be that. If it is not open the console (F12
browser), reload the screen, try to use and put what appears.– Fernando Cordeiro
The link you provided is localhost, it is not possible to access it over the internet, IE we do not have access to it. I noticed that you forgot to close HTML with
</html>
. Note . php there is PHP content?– Guilherme Nascimento