Welcome Guest, Not a member yet? Register   Sign In
Mixing controller form processing and form displaying ?
#1

[eluser]Rushino[/eluser]
Hello,

Would like to know if its okay to mix the controller form processing action method with the form displaying action method ? That would mean that i have only one method called account/registration and the form post data to the same method for displaying errors.

It is possible to know when the user actually process the form ? Since first time i will visit account/registration.. the method return a view with the form (but in the background it still process the form running the $this->form_validation->run() method, it return the form because nothing have been entered but doesnt show any errors.. (which is okay) However when there is an error i would love to show some message before the errors such 'There has been errors validating this form.. etc.' so is there a way to tell the user only shown the form the first time (so don't show the message) then if it process the form and there is an error show the message.

Would it be better to have a method that show the form and a method that process the form instead ?

Hope i am clear.

Thanks.
#2

[eluser]oppenheimer[/eluser]
There is one controller in the example shown in the user's guide for validation:

<a href="http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html">http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html</a>

The validation check will be FALSE for two conditions:
1 - the first time through so the form can be displayed
2 - when the user submits a form with errors.

You will need a second check to determine which of these conditions exist.

Code:
if ($this->form_validation->run() == FALSE)
    if ($this->input->post('submit'))
    {
         [DISPLAY ERROR]
    }
else
    {
         $this->load->view('myform');
    }

Although why wouldn't you want to redisplay the form with the error and repopulate the form with the submitted data as shown in the example in the user's guide?




Theme © iAndrew 2016 - Forum software by © MyBB