[eluser]reaper_unique[/eluser]
First of all, Hi, just registered.
Second, my problems.
I use codeIgniter2 + smarty3
I have a simple contact form in my tpl file with three fields,
- name
- email
- message
Code:
{* Extend our master template *}
{extends file="master.tpl"}
{block name=activeContact}{$activeContact}{/block}
{block name=title}{$title}{/block}
{block name=content}
<form action="{$formAction}" method="post" id="contactForm" enctype="multipart/form-data" class="last">
<fieldset>
<p class="oneHalfCol">
<label for="name"><span class="message_error" id="msgname">Name</span></label>
<input type="text" name="name" id="name" value="" />
</p>
<p class="oneHalfCol">
<label for="email"><span class="message_error" id="msgemail">e-mail</span></label>
<input type="text" name="email" id="email" value=""/>
</p>
<p>
<label for="message"><span class="message_error" id="msgMessage">message</span></label>
<textarea name="message" id="message" rows="10" ></textarea>
</p>
<input type="submit" id="btnContact" class="submit redButton left" name="btnContact" value="Send" />
</fieldset>
</form>
{/block}
and this is the index function:
Code:
public function index() {
if(($this->uri->segment(1)) == "contact") {
$data['activeContact'] = " class=\"active_page\" ";
}
// data for the contact template
$this->smarty->assign('formAction', 'contact/do_sendMail'); //did it like this to test smarty
$data['title'] = "Contact - Let's keep in touch";
// Load the template from the views directory
$this->parser->parse("contact.tpl", $data);
}
When the contact page loads I set form validation in my controller contact.php.
You fill in form and press Send.
Here is where the problems start.
When you press send you go to the do_sendMail() function:
Code:
function do_sendMail() {
$this->load->library('form_validation');
$this->load->library('email');
// field name, error message, validation rules
$this->form_validation->set_rules('name', 'Name', 'trim|required');
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
$this->form_validation->set_rules('message', 'contact message', 'trim|required');
//get the post values of the input fields
$name = $this->input->post('name');
$email = $this->input->post('email');
$message = $this->input->post('message');
if($this->form_validation->run() == TRUE) {
$this->email->set_newline("\r\n");
$this->email->from($email, $name);
$this->email->to('[email protected]');
$this->email->subject("Contact message from $name");
$this->email->message($message);
$send = $this->email->send();
if ($send == true){
$data['activeContact'] = " class=\"active_page\" ";
$data['title'] = "Contact - Thank you for your message";
$this->parser->parse("contactSucces.tpl", $data);
}
}
if($this->form_validation->run() == FALSE) {
$data['name'] = $name;
$data['email'] = $email;
$data['message'] = $message;
$data['title'] = "Contact";
$data['activeContact'] = " class=\"active_page\" ";
$this->smarty->assign('formAction', 'contact/do_sendMail');
$this->parser->parse('contact.tpl', $data);
}
}
The tpl loads but without the css and the url is still contact/do_sendMail.
Form validation doesn't do anything, the fields don't get repopulated and I don't have any CSS.
How do I solve these problems. I've been using codeIgniter2 for a week now, I've followed the tuts on net.tutsplus.com BTW.
I'm getting annoyed.