Welcome Guest, Not a member yet? Register   Sign In
Problem with set_value() of Form Validation
#1

[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>
&lt;?php echo form_dropdown('cod_categorias', $selectCategorias, set_value('cod_categorias'), 'onchange="selectSubcategoria(this.value);"'); ?&gt;
</p>
<p>
<label>Subcategoria</label>
<select name="cod_subcategorias" id="cod_subcategorias">                    
</select>
</p>
<p>
<label>Nome do Produto </label>
&lt;input name="nome_produtos" type="text" id="nome_produtos" value="&lt;?php echo set_value('nome_produtos'); ?&gt;" maxlength="200" /&gt;
</p>
<p>
<label>Url-Amigável </label>
&lt;input name="nome_amigavel_produtos" type="text" id="nome_amigavel_produtos" value="&lt;?php echo set_value('nome_amigavel_produtos'); ?&gt;" maxlength="250" /&gt;
</p>
<p>

<label>Cód. Interno </label>
&lt;input name="cod_interno_produtos" type="text" id="cod_interno_produtos" value="&lt;?php echo set_value('cod_interno_produtos'); ?&gt;" maxlength="150" /&gt;
</p>
<p>
<label>Descrição do Produto </label>
&lt;textarea name="descricao_produtos" id="descricao_produtos"&gt;&lt;?php echo set_value('descricao_produtos'); ?&gt;&lt;/textarea&gt;
</p>
<p>
<label>Especificação do Produto </label>
&lt;textarea name="especificacao_produtos" id="especificacao_produtos"&gt;&lt;?php echo set_value('especificacao_produtos'); ?&gt;&lt;/textarea&gt;
</p>                                                        
<p class="pbotoes">
&lt;input name="btnSalvar" class="botoes" type="submit" value="Salvar" /&gt;
</p>
<p>
<div id="msg">&lt;?php echo !empty($msg) ? utf8_encode($msg) : NULL; echo utf8_encode(validation_errors()); ?&gt;</div>
</p>                        
&lt;/form&gt;

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!


Messages In This Thread
Problem with set_value() of Form Validation - by El Forum - 03-28-2009, 06:59 PM
Problem with set_value() of Form Validation - by El Forum - 03-31-2009, 06:44 PM
Problem with set_value() of Form Validation - by El Forum - 05-19-2009, 07:11 AM
Problem with set_value() of Form Validation - by El Forum - 02-07-2010, 10:13 AM
Problem with set_value() of Form Validation - by El Forum - 05-30-2011, 04:31 PM
Problem with set_value() of Form Validation - by El Forum - 08-03-2011, 08:37 AM
Problem with set_value() of Form Validation - by El Forum - 08-03-2011, 03:59 PM



Theme © iAndrew 2016 - Forum software by © MyBB