Welcome Guest, Not a member yet? Register   Sign In
Recieving form data

[eluser]Random dude[/eluser]
Hello, I just started using CodeIgniter and I'm very happy.
I'm going to be using on http://ducatiadelaide.com.au for the new cms.

In MVC its, class > function > data - not understanding this, I made my first controller <b>have a function that accepts form data</b>

class Do_Everything extends Controller //etc
function show_something() {
//load a view
function edit_something() {

//receive form data

//load a model, edit db

The target of the form I tried to use was "domain/index.php/do_everything/edit_something
However, I've found functions can't be called when sending POST data.

Is this approach completely incorrect?
Do you need a <b>separate controller to receive <i>each</i> form?</b>

Right now I'm going to create a separate controller to accept the form data and call the model from there.

What is the standard approach to accepting forms in CodeIgniter?

[eluser]The Casual Bot[/eluser]
MVC = model view controller

you should be loading a view from your controller which contains the form

then in you controller have a function to take the data ie


class Do_Everything extends Controller {

    function Do_Everything(){

    function index(){

      $this->load->model('viewfile'); //the view with the form

    function formaction(){

//code for dealing with form data you can use $_POST to get at your form data




and your form action should be "formaction"

[eluser]Random dude[/eluser]
Ahh, so after you load a view, the controller is still 'active' so to speak.

So to have a <b>function</b> of a controller handle a form, you need to have the action as the name of the controller thats currently active?

I've just noticed you have $this->load-><b>model</b>('viewfile'); - is model supposed to be view in this case?

Thank you very much for your help.

[eluser]The Casual Bot[/eluser]
lol yeah it should say view

my fault for copy and pasting

you kinda got the idea

when a controller is loaded
ie: www.sitename.com/imdex.php/Do_Everything

the index function is load automatically

but when you submit your form it will change the url to


this then will access you formaction function

so a controller can handle multiple forms and actions

hope this helps

Theme © iAndrew 2016 - Forum software by © MyBB