Welcome Guest, Not a member yet? Register   Sign In
Repopulate and load new template
#1

[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>
                    &lt;input type="text" name="name" id="name" value="" /&gt;
                </p>
        
                <p class="oneHalfCol">
                    <label for="email"><span class="message_error" id="msgemail">e-mail</span></label>
                    &lt;input type="text" name="email" id="email" value=""/&gt;
                </p>
                            
                <p>
                    <label for="message"><span class="message_error" id="msgMessage">message</span></label>
                    &lt;textarea name="message" id="message" rows="10" &gt;&lt;/textarea>
                </p>
                
                &lt;input type="submit" id="btnContact" class="submit redButton left" name="btnContact" value="Send" /&gt;
            </fieldset>            
        &lt;/form&gt;            
{/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.
#2

[eluser]R_Nelson[/eluser]
i had a similar problem i just used if($this->email->send()) instead of setting a var! and i never get multi mails. I don't see why that made a difference but it did.
#3

[eluser]reaper_unique[/eluser]
Thanks for the reply. It's fixed, it was something with the if else. Really weird, but I still have two other problems.
#4

[eluser]reaper_unique[/eluser]
Problem solved, I dropped smarty3. Added a small library that I found on this forum to make a master file, which is all I need because codeIgniter is already great.




Theme © iAndrew 2016 - Forum software by © MyBB