I have developed a contact form which incorporates CI form validation, email helper and class. When the user sends the information the client will receive a HTML email with this information. I have already created a separate view with the HTML table structure and this is built through a string in the controller [code below]. Is there any way of passing what the user has sent into this HTML form? For example in my email I have:
-You have received an email from $name<br>
-Message $message<br>
-You can reply to them at $email
It would be great if someone could guide me. I have included important snippets of code as a guide.
View:
<h1>Contact</h1>
<div id="contact">
<?php
echo $message;
echo validation_errors();
echo form_open('contact/send_email');
//Name field
echo form_label('Name: ', 'name');
$data = array (
'name' => 'name',
'id' => 'name',
'value' => set_value('name')
);
echo form_input($data);
echo form_submit('submit', 'Send');
echo form_close();
Controller:
At the top of this code is the form validation and if else statements, and this is what happens when it has passed validation checks:
}else{
$data['message'] = 'The email has successfully been sent';
$html_email = $this->load->view('html_email', $data, true);
//load the email class
$this->load->library('email');
$this->email->from(set_value('email'), set_value('name'));
$this->email->to('email@hotmail.com');
$this->email->subject('Message from Website');
$this->email->message($html_email);
$this->email->send();
//if error from library will send us metadata
echo $this->email->print_debugger();
$data['page_title'] = 'Contact';
$data['content'] = 'contact';
$this->load->view('template', $data);
}
Doing things the CodeIgniter way you should use
$this->input->post('name')instead of$_POST['name']To get the data to your view just add
$data['name'] = $this->input->post('name');Before you load your view. This will allow you to print the
$namevariable in the view as in your initial statement. I.e. in the view:You have a message from <?=$name?>In the controller I would also change
set_value('name')for$this->input->post('name').