Run functions in index method - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Run functions in index method (/showthread.php?tid=35754) |
Run functions in index method - El Forum - 11-10-2010 [eluser]Casperlarsen94[/eluser] As i mention in my last topic i'm quite new in Codeigniter. Is it possible to run a validation or something like that in a index method like this Code: function index() When i'm trying to do it, it shows my register form twice? Anyone who can help me? Thanks Run functions in index method - El Forum - 11-10-2010 [eluser]prestondocks[/eluser] Can you show us the code in your view and your template. The code in your method looks fine. Simon Run functions in index method - El Forum - 11-10-2010 [eluser]Casperlarsen94[/eluser] If i put this in it: Code: $this->form_validation->set_rules('name', 'Name', 'required|min_length[3]|max_length[40]'); Run functions in index method - El Forum - 11-11-2010 [eluser]prestondocks[/eluser] I cant see anything wrong with that, but that is your controller method. Can you post your view and template files. I think that is where your problem may lie. Thanks Run functions in index method - El Forum - 11-11-2010 [eluser]Casperlarsen94[/eluser] Yes, of course. File view Code: <?php Top of the template Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> Bottom of template Code: </body> The file that merge the top and the bottom of the template together Code: <?php Run functions in index method - El Forum - 11-11-2010 [eluser]prestondocks[/eluser] To be honest I am not quite sure how your controller is setup. it seems that in the index method you are loading the view inside a template, but in the form validation script you are loading the view directly with out the template. Is your form validation code inside the index method or the validate method? If the form validation code is also inside the index method then it looks as though you will be loading the register_view file twice. Sorry I can help more than that. Simon Run functions in index method - El Forum - 11-12-2010 [eluser]nuwanda[/eluser] Where is your validation? In the index method? That won't work. You need a method in your controller that will take the post data from your view. Then you validate the data. Code: function process_form(){ Run functions in index method - El Forum - 11-12-2010 [eluser]techgnome[/eluser] nuwanda - why not? seems reasonable to me. Casper - a couple things - 1) I don't see where you pass $content to the template. 2) Your form is posting to a validate method... so what did you post? The validate method or the index method? Can you post your ENTIRE method? You post one set of code in the first post, then posted more code, with the comment of "If i put this in it:" w/o explaining HOW you put it all together. -tg Run functions in index method - El Forum - 11-12-2010 [eluser]nuwanda[/eluser] [quote author="techgnome" date="1289593253"]nuwanda - why not? seems reasonable to me.[/quote] It's not that it won't actually work, I just don't think it works in terms of good design. I use the index method for setting up page data and loading the initial view. Now that view might contain a form which then has its action set to a method in the controller, not the index method. That just makes more design sense to me. Run functions in index method - El Forum - 11-12-2010 [eluser]techgnome[/eluser] OK... I buy that... in that sense, yes I'd agree. -tg |