Welcome Guest, Not a member yet? Register   Sign In
How to use validator
#1

[eluser]il_dandi[/eluser]
Hi!!!

How Can I manage the validation… I would like apply CSS on the textbox and combobox border

in my controller I've:

Code:
function add()
    {    
        $this->load->helper('form');
                        
        if ( ! $this->_validate_form() )
        {
            $this->template->write_view('content', 'admin/avatar', $data, TRUE);
            $this->template->render();
        }
        else
        {
            $id = $this->avatars_model->add_entry();
            $this->session->set_flashdata('msg', 'OK');
            redirect(base_url()."admin/avatars");
        }                
    }


    function _validate_form()
    {
        $rules = array(
                'firstname'        =>    'trim|required|strip_tags|xss_clean|max_length[30]',
                'lastname'        =>    'trim|strip_tags|xss_clean|max_length[500]'
        );
        $this->validation->set_rules($rules);
        
        $fields = array(
                'firstname'            =>    'fistname',
                'lastname'            =>    'lastname',
                'age'                =>    'age'
        );
        $this->validation->set_fields($fields);
        
        return ($this->validation->run() == FALSE) ? FALSE : TRUE;    
    }

in the view I have

Code:
<?php $v =& $this->validation ?>

...

  <td align="right">cognome: </td><td>&lt;input name="lastname" type="text" id="lastname" size="30" maxlength="255" value="&lt;?=$lastname?&gt;" class="&lt;?=$v-&gt;lastname_error?&gt;" ></td>
  </tr>
...

I would like to see the textbox with a red border...as I've seen in many examples (linkster...)



how can I apply the CSS?? In HTML code of linkster example I’ve

<label for=“title”>* Title: </label>&lt;input type=“text” name=“title” value=”” id=“title” class=“field_error” /&gt;&lt;/p>


in my HTML code I’ve

<td>&lt;input type=“text” value=”” name=“lastname” class=“” /&gt;&lt;/p>

Thanks for help me!!!
#2

[eluser]pistolPete[/eluser]
Use the new Form validation library.

In your view:
Code:
<td align="right">cognome: </td><td>&lt;input name="lastname" type="text" id="lastname" size="30" maxlength="255" value="&lt;?php echo set_value('lastname'); ?&gt;" class="&lt;?php echo ( form_error('lastname') == '') ? '': 'your_error_css_class' ;?&gt;" &gt;&lt;/td>
#3

[eluser]il_dandi[/eluser]
thanks thanks thanks ... I've only to modify my view as you have written in your post??

nothing else?? all other my code is it OK?

thanks
#4

[eluser]pistolPete[/eluser]
No, if you want to use set_value() and form_error() you have to use the new Form validation library, as I wrote above.




Theme © iAndrew 2016 - Forum software by © MyBB