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

#1
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'>
<head>
<title>untitled</title>
<style type = 'text/css'>
label {display:black;}
</style>
</head>

<body>

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

<?php

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

?>

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

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

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

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

Any ideas?
Reply

#2
Is there a controller Email with the Method send?

Reply

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

class Email extends CI_Controller
{


function index()
{
$this->load->view('newsletter');
}

function send()
{
$this->load->library('form_validation');

$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)
{
$this->load->view('newsletter');
}
else
{
$name = $this->input->post('name');
$email = $this->input->post('email');

$this->load->library('email');
$this->email->set_newline("\r\n");

$this->email->from('myemail@gmail.com', 'My Email Name');
$this->email->to($email);
$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';

$this->email->attach($file);

if($this->email->send())
{
echo 'Your email was sent';
}
else
{
show_error($this->email->print_debugger());
}
}


}
}
Reply

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

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

Reply

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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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