I'm trying to fix validation problems of my code, at first I did the test only with the label "Name", where it is required and can not contain numbers or characters, but is registering EVERYTHING.
How can I fix it?
Index Controller
public function submit(){
$result = $this->m->submit();
// TESTE DE VALIDAÇÃO
$this->form_validation->set_rules('txt_nome', 'Nome', 'trim|required');
if( $this->form_validation->run() ){
// echo 'Success';
$this->session->set_flashdata('msg_sucesso', 'Registro adicionado com sucesso!');
}else{
//echo validation_errors();
$this->session->set_flashdata('erro_msg', 'Erro ao adicionar registro.');
}
redirect(base_url('estado'));
}
Form
<form action="<?php echo base_url('estado/submit'); ?>" method="post" class="form-horizontal">
<div class="form-group">
<label for="nome" class="col-md-1 text-right">Nome</label>
<div class="col-md-10">
<input type="text" name="txt_nome" value="<?php echo set_value('txt_nome'); ?>" class="form-control" required>
<td><?php echo form_error('txt_nome'); ?></td>
</div><!-- col-md-10 -->
</div><!-- form-group -->
<div class="form-group">
<label class="col-md-1 text-right"></label>
<div class="col-md-10">
<input type="submit" name="btnCadastro" class="btn btn-primary" value="Cadastrar">
</div><!-- col-md-10 -->
</div><!-- form-group -->
</form><!-- form -->