0

In my controller i have a view for registering new members.

Instead of making a whole new function for that such as,

public function show_registration(){
$this->load->view('registration');
}

public function validate_registration(){

}

Instead of doing the one above where i make a function to show the view then a new one to receive the data from the view, i made it like this.

public function registration(){
if(array_key_exists('submit',$_POST)){
/////if exist process the data here
}else
$this->load->view('registration');
}

The above if statement, checks if ever there was data submitted to the function if not then it would show the view else it will process the data.

It seems like more of an ideal way right? then i thought, what if this could cause problems?

Is there any chance or possibility this might ruin my project? I am starting right now, and i just want insights whether i should pursue my current way or i should just create a separate one for showing the view.

**EDIT: I just realized, this does not necessarily check all submitted data, but only data submitted by the button of the name 'submit', so as long as i keep the name of the submit button for every form unique as possible then i should be fine.

sample: form for registration, button name should be registration.**

7
  • you should use codeigniter form validation class, it is exactly what you need: ellislab.com/codeigniter/user-guide/libraries/… Commented Mar 18, 2014 at 8:21
  • I'd start by using input class since it has some useful filters and check out validation class for forms as well. ellislab.com/codeigniter/user-guide/libraries/input.html ; ellislab.com/codeigniter/user-guide/libraries/… Commented Mar 18, 2014 at 8:22
  • How should i use it? my point is to check if there was data submitted. I dont know how validation comes into play with this. Commented Mar 18, 2014 at 8:23
  • $this->form_validation->run() is done for that, if it's true, the form was submited Commented Mar 18, 2014 at 8:23
  • But thats too ambigous right? i mean, if there was data submitted by another form? That was my concern. although i dont know how it would occur, i just am making sure Commented Mar 18, 2014 at 8:24

2 Answers 2

1

Here is an example of what you can do with codeigniter

class Form extends CI_Controller {

    function index()
    {
        $this->load->helper(array('form', 'url'));

        $this->load->library('form_validation');

        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('myform');
        }
        else
        {
            $this->load->view('formsuccess');
        }
    }
}
Sign up to request clarification or add additional context in comments.

3 Comments

What does validatio run do exactly? My main idea of it is to run the set rules i declared, or am i wrong?
please read the documentation here: ellislab.com/codeigniter/user-guide/libraries/…
It would be nice if you could stop sending me links to the documentation, i am currently on it. As i said on my post, i am asking for insights.
-1

Using Codeigniter you have to follow codeigniter-form-validation for loading a view or submitting your form for more information visit this Codeigniter form_validation library

1 Comment

Welcome to Stack Overflow! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.