Welcome Guest, Not a member yet? Register   Sign In
form validation - validation error before form submit
#1

[eluser]jahboite[/eluser]
I'm using the form helper and form validation, but I get differences on loading the page between my webserver at home (php5) and my hosted webserver php4.

Here's a snippet from my controller:
Code:
function index()
    {
        // load form helper
        $this->load->helper('form');
        $this->load->library('validation');
        
        // form validation
        $rules['dname'] = "trim|required|min_length[5]|max_length[255]|xss_clean";
        $rules['description'] = "trim|required|min_length[5]|max_length[1024]|xss_clean";
        $this->validation->set_error_delimiters('<p class="frm_valid_err">', '</p>');
        $this->validation->set_rules($rules);

        $fields['dname'] = 'DName';
        $fields['description'] = 'Description';
        $this->validation->set_fields($fields);

        if ($this->validation->run() == FALSE)
        {
            $page_data['page_title'] = 'View A';
            $this->load->view('a_vw',$page_data);
        }
        else
        {
            
            $page_data['page_title'] = 'View B';
            $this->load->view('b_vw',$page_data);
        }
    }
Here's a snippet from my view
Code:
&lt;?php
    echo $this->validation->error_string;
    
    $form_attributes = array('id' => 'form_id');
    $form_hidden = array('user_name' => getUnamefromUid($user), 'user_id' => $user);
    
    // form submits to self i.e. function index()
    echo form_open('',$form_attributes,$form_hidden);
    
    if ($this->validation->dname)
    {
        $dname_value = $this->validation->dname;
    }
    else
    {
        $dname_value = 'Type something here';
    }
    
    if ($this->validation->description)
    {
        $dscr_value = $this->validation->description;
    }
    else
    {
        $dscr_value = 'Type something here';
    }
        
    
    $text_name = array(
                  'name' => 'dname',
                  'id' => 'dname',
                  'value' => $dname_value,
                  'rows' => '2',
                  'cols' => '60',
                  'style' => 'width:100%',
                );
    
    $text_descr = array(
                  'name' => 'description',
                  'id' => 'description',
                  'value' => $dscr_value,
                  'rows' => '3',
                  'cols' => '60',
                  'style' => 'width:100%',
                );
    
    echo form_textarea($text_name);
    echo form_textarea($text_descr);
    echo '<br />'.form_submit('', 'Submit!');
    echo form_close();

?&gt;
There's another view (View B) which just echos "Success!".

On my webserver at home, I get the behaviour I expect.

On the hosted box, I get a "must have a value" validation error for both of the fields when I load View A, before I've even submitted the form.

Is this likely to be something to do with the version of php, my code, or the fact that the page is being rendered by facebook.


Messages In This Thread
form validation - validation error before form submit - by El Forum - 10-21-2007, 03:22 PM
form validation - validation error before form submit - by El Forum - 10-21-2007, 07:54 PM



Theme © iAndrew 2016 - Forum software by © MyBB