• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with form_submit()

I'm having a bit of trouble with form_submit(). Here's my issue: i have 2 php files. My controller is called email.php and my view is called newsletter.php (if anyone has seen Code Igniter from Scratch Day 4, this is that tutorial)..

I have created a form for the user to enter their Name, Email Address, and then to press Submit in my newsletter.php file, which should take them to the function send() in my email.php file. When the user clicks Submit, I get a 404 Page Not Found error. I've copied the code for my newsletter.php file below:

<html lang='en'>
<style type = 'text/css'>
label {display:black;}


<div id="newsletter_form">
<?php echo form_open('email/send'); ?>


$name_data = array(
'name' => 'name',
'id' => 'name',
'value' => set_value('name')


<p><label for="name">Name: </label><?php echo form_input($name_data); ?></p>

<label for="name">Email Address: </label>
<input type = 'text' name = 'email' id = 'email' value = '<?php echo set_value('email'); ?>'>

<?php echo form_submit('submit', 'Submit'); ?>

<?php echo form_close(); ?>
<?php echo validation_errors(); ?>
</div><!--end newsletter-form-->

Any ideas?

Is there a controller Email with the Method send?


Yes. Here's the code from the controller with that function:

class Email extends CI_Controller

function index()

function send()

$this->form_validation->set_rules('name', 'Name', 'trim|required');
$this->form_validation->set_rules('email', 'Email Address', 'trim|required|valid_email');
if($this->form_validation->run() == FALSE)
$name = $this->input->post('name');
$email = $this->input->post('email');


$this->email->from('[email protected]', 'My Email Name');
$this->email->subject('Hey, from Codeigniter');
$this->email->message('It is working');

/*attachments */

$path = $this->config->item('server_root');
echo $path;
$file = $path . '/ci/attachments/yourinfo.txt';


echo 'Your email was sent';


Have you set a htacces file in you root to get rid of index.php?

PHP Code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
^(.*)$ index.php?/$[L


Thanks, that fixed it. it was just creating a url that would do index.php/index.php so it would give a 404 error

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.