It looks like you're new here. If you want to get involved, click one of these buttons!
<div class="contactform">
{$load->helper('form')}
{form_open('email/send')}
{$name_data = array(
'name' => 'name',
'id' => 'name',
'value' => set_value('name'),
'class' => 'contact'
)}
<p>{form_error('name')}<label for="name">Name: </label>{form_input($name_data)}</p>
<p>{form_error('email')}
<label for="name">Email Address: </label>
<input type="text" class="contact" name="email" id="email" value="{set_value('email')}">
</p>
<p>{form_error('email_again')}
<label for="name">Email Again, Please:</label>
<input type="text" class="contact" name="email_again" id="email_again" value="{set_value('email_again')}">
</p>
<p>
<label for="name">Subject:</label>
<input type="text" class="contact" name="subject" id="subject" value="{set_value('subject')}">
</p>
<p>{form_error('message')}
<label for="name">Message:</label>
<input type="textarea" rows="5" class="contact" name="message" id="message" value="{set_value('message')}">
</p>
<p>{form_submit('submit', 'Submit')}</p>
{form_close()}
</div><!--end Contact-block-->
<?php
/**
* Sends email
*/
class Email extends CI_Controller
{
function __construct()
{
parent::__construct();
}
function index()
{
$this->load->view('contact_form');
}
function send()
{
$this->load->library('form_validation');
// field name, error message, validation rules
$this->form_validation->set_rules('name', 'Name', 'trim|required');
$this->form_validation->set_rules('email', 'Email Address', 'trim|required|valid_email|matches[email_again]');
$this->form_validation->set_rules('email_again', 'Email Again, Please', 'trim|required');
$this->form_validation->set_rules('subject', 'Subject', '');
$this->form_validation->set_rules('message', 'Message', 'trim|required');
if($this->form_validation->run() == FALSE)
{
$this->load->view('contact_form');
}
else
{
// validation has passed. Now send the email
$name = $this->input->post('name');
$email = $this->input->post('email');
$subject = $this->input->post('subject');
$message = $this->input->post('message');
$this->load->library('email');
$this->email->set_newline("\r\n");
$this->email->to('info@somesite.com');
$this->email->from('admin@somesite.com', 'Admin');
$this->email->reply_to($email);
$this->email->subject($subject);
$this->email->message($message);
$path = $this->config->item('server_root');
if($this->email->send())
{
$this->load->view('message_sent');
}
else
{
show_error($this->email->print_debugger());
}
}
}
}
Comments
$this->session->set_flashdata('error', 'No good'); redirect(current_url());
You could have your contact form as a block or straight in the layout too. Another way again.. could ajax the contact form submit and just pipe a json response back.
The code tags are: without hyphens.