1

I have a codeigniter application that is effectively just a one-page form that takes in info and sends an e-mail. I created a method that is intended to handle form submission and send the e-mail called "submit", but for some reason this method appears not to do anything at all.

Here's my controller code:

class Main extends CI_Controller {

public function __construct() {
    parent::__construct();
}

public function index($page = "home") {
    // Loading the form view.
    $this->load->view($page);
}

// This is the method that doesn't do anything.
public function submit() {

    // I would be processing post data from the form here, 
    // but right now I'm just trying to load 
    // a view in this method to see if it's working
    $this->load->view("form_submit");
}

My view is using the CodeIgniter form_open function to create the form, and looks as follows:

echo form_open("main/submit/");

This, to my understanding, is how one is supposed to use the form_open function to provide an action to the form.

The form opening tag looks like this when the view is accesssed.

<form action="http://localhost:81/project1/main/submit" method="post" accept-charset="utf-8">

The action and method in the form tag appears to be correctly set, but when clicking on submit on the form the home view just refreshes. Additionally, if I try to directly navigate to "home/submit/" it just loads the home view again. I'm starting to go a little crazy on this and I'm sure I'm missing something really simple.

morris295
  • 517
  • 1
  • 7
  • 21
  • 1
    what does your routes file look like? – swatkins May 22 '15 at 13:09
  • The pertinent details in the routes file: $route['default_controller'] = 'main';$route['404_override'] = '';$route['translate_uri_dashes'] = FALSE; – morris295 May 22 '15 at 13:11
  • Added that to the route, tried loading "main/submit" directly, nothing happens. EDIT: Also, adding index.php to the url doesn't appear to change anything. Adding "index.php" to the config file as the index page also has no effect. – morris295 May 22 '15 at 13:14
  • You just get a blank page ? so [Use this answer](http://stackoverflow.com/a/6575502/3152155) an replace the code in your index.php in block case 'development' then update your question with the error you get – Mohammadhzp May 22 '15 at 13:17
  • @Mohammadhzp I'm not getting a blank page, I'm getting the "home" view no matter what I do, whether submitting the form or trying to directly access "home/submit" in the browser. The environment is set to "development" but no errors are being returned. I also checked the php error log, and there's nothing there concerning today's date or this site on my local machine. – morris295 May 22 '15 at 13:22
  • Do you have the [profiler](https://ellislab.com/codeigniter/user-guide/general/profiling.html) turned on? If not, add this to your controller: `$this->output->enable_profiler(TRUE);` and let us know the output. – swatkins May 22 '15 at 14:02
  • Add in route table $route['main/submit'] = 'main/submit'; – splash58 May 22 '15 at 14:54
  • I managed to solve this. While it's not an explanation of why this was occurring, I grabbed a clean version, read: without any of my config changes, of the framework from the zip file and placed my controller and view code into it. It appears that something was definitely incorrect in configuration or some other part of the framework thanks to my meddling. At this point I'm able to submit the form without a problem. – morris295 May 22 '15 at 18:05

0 Answers0