CodeIgniter Forums
Help with form_submit() - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11)
+--- Thread: Help with form_submit() (/showthread.php?tid=400)



Help with form_submit() - roonietunes - 11-29-2014

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?


RE: Help with form_submit() - Rufnex - 11-29-2014

Is there a controller Email with the Method send?


RE: Help with form_submit() - roonietunes - 11-30-2014

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('[email protected]', '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());
}
}


}
}


RE: Help with form_submit() - Rufnex - 12-01-2014

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



RE: Help with form_submit() - roonietunes - 12-01-2014

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