[eluser]Italo Domingues[/eluser]
Good evening, I wish to inform a problem in the method set_Value () the library form_validation. I have the following form. And I got the script for the validation of some required fields (scripts below). The problem that occurs is, if I fill out the form and leave a required field not filled, it makes the validation perfectly, but when he return to form, the set_Value () returns only the data that are in the script validation, for example, if I enter something in the specification of the product, so it makes the validation of the fields, and return again to the form stating that there is a mandatory field not filled, the field specification of the product does not return what was entered, even though the set_Value () in the attribute value of the input. This is normal?
Form
Code:
<?php echo form_open('admin/produtos/cadastrar', array('id' => 'form_cadastro_produto', 'onSubmit' => 'cadastrarProduto(); return false;')); ?>
<p>
<label>Categoria</label>
<?php echo form_dropdown('cod_categorias', $selectCategorias, set_value('cod_categorias'), 'onchange="selectSubcategoria(this.value);"'); ?>
</p>
<p>
<label>Subcategoria</label>
<select name="cod_subcategorias" id="cod_subcategorias">
</select>
</p>
<p>
<label>Nome do Produto </label>
<input name="nome_produtos" type="text" id="nome_produtos" value="<?php echo set_value('nome_produtos'); ?>" maxlength="200" />
</p>
<p>
<label>Url-Amigável </label>
<input name="nome_amigavel_produtos" type="text" id="nome_amigavel_produtos" value="<?php echo set_value('nome_amigavel_produtos'); ?>" maxlength="250" />
</p>
<p>
<label>Cód. Interno </label>
<input name="cod_interno_produtos" type="text" id="cod_interno_produtos" value="<?php echo set_value('cod_interno_produtos'); ?>" maxlength="150" />
</p>
<p>
<label>Descrição do Produto </label>
<textarea name="descricao_produtos" id="descricao_produtos"><?php echo set_value('descricao_produtos'); ?></textarea>
</p>
<p>
<label>Especificação do Produto </label>
<textarea name="especificacao_produtos" id="especificacao_produtos"><?php echo set_value('especificacao_produtos'); ?></textarea>
</p>
<p class="pbotoes">
<input name="btnSalvar" class="botoes" type="submit" value="Salvar" />
</p>
<p>
<div id="msg"><?php echo !empty($msg) ? utf8_encode($msg) : NULL; echo utf8_encode(validation_errors()); ?></div>
</p>
</form>
Script
Code:
function _verificar_campos()
{
$rules = array(
array(
'field' => 'cod_categorias',
'label' => 'Categoria',
'rules' => 'required'
),
array(
'field' => 'cod_subcategorias',
'label' => 'Subcategoria',
'rules' => 'required'
),
array(
'field' => 'nome_produtos',
'label' => 'Nome do Produto',
'rules' => 'required'
),
array(
'field' => 'nome_amigavel_produtos',
'label' => 'Url-Amigável',
'rules' => 'required'
),
array(
'field' => 'descricao_produtos',
'label' => 'Descrição do Produto',
'rules' => 'required'
),
array(
'field' => 'peso_produtos',
'label' => 'Peso do Produto',
'rules' => 'required|numeric'
),
array(
'field' => 'preco_produtos',
'label' => 'Preço do Produto',
'rules' => 'required|numeric'
),
array(
'field' => 'mostrar_preco_produtos',
'label' => 'Mostrar Preço',
'rules' => 'required'
),
array(
'field' => 'imagem_principal_produtos',
'label' => 'Imagem Principal',
'rules' => 'required'
),
array(
'field' => 'ativo_produtos',
'label' => 'Status',
'rules' => 'required'
)
);
$this->form_validation->set_rules($rules);
if ($this->form_validation->run() === FALSE)
{
return FALSE;
}
else
{
return TRUE;
}
}
PS: I had to draw some lines of form because it does not fit in the post!