Welcome Guest, Not a member yet? Register   Sign In
Form validation with a function argument
#1

[eluser]Unknown[/eluser]
Hello,

I have a table of database rows in my first view. here i have a link to update for every row with different id's.

when i click this i get to a new view with the filled out form of data i want to validate
with the url /controller/update_function/rowid.

Now when i submit this form with the new data, it posts the data to the same url again.

Controller code:

Code:
function update_tournament($id)
    {
        if(!$this->input->post())
        {
            $cssfilename = array('css' => 'tournaments.css', 'id' => $id, 'row' => $this->get_tournament_by_id($id));
            $this->masterpage->setMasterPage ( 'v_master' );
            $this->masterpage->addContentPage ( 'v_update_tournament', 'content', $cssfilename );
            $this->masterpage->show();
        }
        else
        {
            if($this->form_validation->run() == FALSE)
            {
                $this->session->set_flashdata('errors', array('tournament' => form_error('tournament_name'), 'buyin' => form_error('buyin'), 'rake' => form_error('rake')));
                redirect(sprintf('tournaments/update_tournament/%d', $id));
            }
            else
            {
            }
        }
}

Now the form_validation.php file ruleset requires the function call to match exactly to run the validation check. But my id is going to be different depending on wich row im trying to update.

form_validation.php code:

Code:
'tournaments/update_tournament/*' => array(
                                                  array(
                                                          'field' => 'tournament_name',
                                                          'label' => 'Namn',
                                                          'rules' => 'trim|required'
                                                       ),
                                                  array(
                                                          'field' => 'buyin',
                                                          'label' => 'Buyin',
                                                          'rules' => 'required|numeric'
                                                       ),
                                                  array(
                                                          'field' => 'rake',
                                                          'label' => 'Rake',
                                                          'rules' => 'required|numeric'
                                                       )                                    
                                                ),

So what id like to be able to do is use a wildcard after the url in the validation file

Like so: controller/update_function/* so it runs no matter what the argument is.

can i use a wildcard of some sort in my validation rules file? Or must i solve it some other way.

One way would be to set the validation rules manually in that function, but preferrable i would like to keep all validation rules in that one file.

I hope im making myself clear. If not ill post anything else you need to know.

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB