Welcome Guest, Not a member yet? Register   Sign In
form validation error return [SOLVED]
#1

[eluser]PV-Patrick[/eluser]
Hello,
I have been searching around here for hours trying to figure this problem out and I can't seem to fix it. In a nutshell, when I click submit to validate my form and it doesn't pass, I don't see the error's at all on the view.

Code:
<?php

class Products extends Controller {

    function Products() {
    
        parent::Controller();
        
        $this->load->database();
        $this->load->helper(array('form','url'));
        $this->load->library('validation');
    }
    
    function index() {
        $data['title'] = "Title";
        
        $this->load->view('products', $data);
    }
    
    function order() {
        $data['title'] = "Title";
        
        $this->load->view('order', $data);
    }
    
    function product_order() {
        $rules['firstname'] = "required|trim|min_length[2]|max_length[25]|alpha_dash";
        $rules['lastname'] = "required|trim|min_length[2]|max_length[25]|alpha_dash";
        
        $this->validation->set_rules($rules);
        
        $fields['firstname']    = 'First Name';
        $fields['lastname']        = 'Last Name';
        
        $this->validation->set_fields($fields);
        
        if($this->validation->run() == FALSE) {

            
            $this->load->view('order');
            
        } else {
            $this->load->view('formsuccess');
        }
    }

}
?>

This is a stripped version of the view page.

Code:
<?=$this->validation->error_string; ?>

<?=form_open('products/product_order', $form_attributes);?>

<table>
    <tr>
        <td><u>Billing Information</u></td>
    </tr>
    <tr>
        <td>First Name:</td>
        <td>&lt;input type="text" name="firstname" size="20" maxlength="25" onClick="loadData(&lt;?=$user_form_data?&gt;)"&gt;</td>
        <td>Last Name:</td>
        <td>&lt;input type="text" name="lastname" size="20" maxlength="25"&gt;</td>
    </tr>
    <tr>
        <td>&lt;?=form_submit('submit_order', 'Submit');?&gt;</td>
    </tr>
</table>
&lt;/form&gt;

Any help would be appreciated, thanks!
#2

[eluser]PV-Patrick[/eluser]
I have tried the example on the User Guide and the validation returns just fine so it must have something to do with the way I have the controller/form setup... Is it possible that I can't do the validation from within a function, it needs to be a class to itself?

Any suggestions would be amazing right now! Smile
#3

[eluser]PV-Patrick[/eluser]
After some line to line modifications to see if I couldn't figure it out I did. I started building off some other suggestions I found in other threads in regards to the placement of the load statement and once I placed the $this->load->library('validation') statement inside each function that needed it, it worked!
#4

[eluser]Grahack[/eluser]
It's quite weird it doesn't work when loading the library in the constructor of the controller.
Please, do you have links to the other threads?
#5

[eluser]PV-Patrick[/eluser]
No, I don't have the links. Sorry Sad

I was just doing a search here for items regarding.... &lt;?=$this->validation->error_string;?&gt;

Search for like error string display




Theme © iAndrew 2016 - Forum software by © MyBB