[eluser]MattHirschfelt[/eluser]
With the amount of information available on the web these days it makes me feel like a failure when I can't solve my own problem. However, I'm pretty new to CI and I'm either not grasping the concepts of how to properly set things up or I'm doing something really dumb that someone can hopefully point out to me so I can have a teaching moment.
First, the page that I'm working on is currently up in it's development form at
http://www.openparser.info/index.php. My goal is to make the form under the "What if I need help?" submit an e-mail to me and then redirect the user back to the same page with either a success or failure error message printed.
My files for this task are as follows:
Relevant portion from views/frontpage.php:
Code:
<?php echo form_open('contact');?>
<fieldset>
<legend>Send Us a Message</legend>
<?php if(isset($errormessage)){echo $errormessage;} ?>
<div class="clearfix">
<label for="name">
Your Name<a tabindex="-1" href="#" rel="tooltip" title="Required Field">*</a>
</label>
<div class="input">
<input type="text" name="contactname" id="contactname" value="" class="span6 required" role="input" aria-required="true" />
</div>
</div>
<div class="clearfix">
<label for="email">
Your Email<a tabindex="-1" href="#" rel="tooltip" title="Required Field">*</a>
</label>
<div class="input">
<input type="text" name="email" id="email" value="" class="span6 required email" role="input" aria-required="true" />
</div>
</div>
<div class="clearfix">
<label for="message">Message<a tabindex="-1" href="#" rel="tooltip" title="Required Field">*</a></label>
<div class="input">
<textarea rows="8" name="message" id="message" class="span10 required" role="textbox" aria-required="true"></textarea>
</div>
</div>
<div class="actions">
<input type="submit" rel="tooltip" value="Send Your Message" name="submit" id="submitButton" class="btn primary" title="Click here to submit your message!" />
<input type="reset" rel="tooltip" value="Clear Form" class="btn" title="Remove all the data from the form." />
</div>
</fieldset>
</form>
controller/frontpage.php:
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Frontpage extends CI_Controller {
public function __construct()
{
parent::__construct();
$URL = explode('.', $_SERVER['HTTP_HOST']);
$this->subdomain = $URL[0];
unset($URL);
}
public function index()
{
$data['extraheaders'] = '[removed]$("[rel=tooltip]").tooltip();[removed]';
if($this->subdomain == "www") {
$this->load->helper('url');
$this->load->helper('form');
$this->view_data['base_url'] = base_url();
$this->load->view('include/header', $data);
$this->load->view('include/navbar');
$this->load->view('frontpage');
$this->load->view('include/footer');
} else {
$this->load->helper('url');
$this->view_data['base_url'] = base_url();
$this->load->view('include/header', $data);
$this->load->view('include/navbar');
$this->load->view('include/subnav');
$this->load->view('include/footer');
}
}
function contact()
{
$this->load->helper('url');
$this->load->helper('form');
$this->load->helper('email');
$this->load->library('email');
$this->load->library('form_validation');
$this->form_validation->set_rules('name', 'Name', 'trim|required|xss_clean');
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
$this->form_validation->set_rules('message', 'Message'. 'trim|required|xss_clean');
if ($this->validation->run()==FALSE){
$data['extraheaders'] = '[removed]$("[rel=tooltip]").tooltip();$(\'#collapseOne\').collapse(\'hide\');$(\'#collapseSix\').collapse(\'show\');[removed]';
$data['errormessage'] = '<p class="alert alert-error">Please check if you’ve filled all the fields with valid information and try again. Thank you.</p>';
$this->view_data['base_url'] = base_url();
$this->load->view('include/header', $data);
$this->load->view('include/navbar');
$this->load->view('frontpage');
$this->load->view('includeYeah/footer');
}
else {
$this->email->from($this->input->post('email'), $this->input->post('name'));
$this->email->to('[email protected]');
$this->email->subject('Open Parser Contact');
$this->email->message($this->input->post('message'));
$data['extraheaders'] = '[removed]$("[rel=tooltip]").tooltip();$(\'#collapseOne\').collapse(\'hide\');$(\'#collapseSix\').collapse(\'show\');[removed]';
$data['errormessage'] = $this->email->send()?'<div class="alert alert-success"><p><strong>Message Successfully Sent!</strong></p><p>Thank you for contacting me! Your email was successfully sent and I’ll be in touch with you soon.</p></div>':'<p class="alert alert-error">There was an error sending your message. Please try again!</p>';
$this->email->clear();
$this->view_data['base_url'] = base_url();
$this->load->view('include/header', $data);
$this->load->view('include/navbar');
$this->load->view('frontpage');
$this->load->view('include/footer');
}
}
}
/* End of file frontpage.php */
/* Location: ./application/controllers/frontpage.php */
Rather than get the expected result of sending the message and redirecting back, I get a mess or errors and problems.
The errors reported are as follows:
Quote:A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /home/matth41/public_html/openparser.info/application/controllers/contact.php:8)
Filename: core/Common.php
Line Number: 438
Quote:404 Page Not Found
The page you requested was not found.
The page also basically prints the contact function on the page.
Thanks for any help!