Welcome Guest, Not a member yet? Register   Sign In
really noob question
#1

[eluser]winterain[/eluser]
Hello all!

I've just gotten myself aqquinted to the MVC way and CI and coding my first site.. however I'm running into some quirks which I'm sure can be easily solved with some enlightening..

This is on a contact page which I have a Email form and a chatbox with insert chat form..

my code is currently structure like this (please correct structure if viable)

Code:
class Contact extends Controller {
    
    function Contact()
    {
        parent::Controller();
        
        $this->load->helper('url');
        $this->load->helper('form');
        $this->load->helper('string');
        $this->load->helper('captcha_lite');
        $this->load->library('email');
        $this->load->library('form_validation');    
        $this->load->model('Chat','',TRUE);
        $this->form_validation->set_error_delimiters('<span>', '</span><br>');
    }

    function index()
    {            
        $data['query'] = $this->Chat->getChat();
        
        $this->load->view('contact_view',$data);
        
        
    }
    
    function insert_email()
    {
        $data['query'] = $this->Chat->getChat();
        
        $this->form_validation->set_rules('name', 'Name', 'required');
        $this->form_validation->set_rules('email', 'Email', 'required|valid_email');
        $this->form_validation->set_rules('verify', 'Verification', 'required');
        $this->form_validation->set_rules('body', 'Talk to us', 'required');
        
        validate_captcha();
                
        if ($this->form_validation->run() == TRUE)
        {
            $this->email->from($_POST['email'], $_POST['name']);
            $this->email->to('[email protected]');
        
            $this->email->subject('You have an email enquiry!');
            $this->email->message($_POST['body']);
            
            $this->email->send();
            
            
            $data['success'] = 'Thank you! Your email has been sent! :)';
                        
            $this->load->view('contact_view',$data);
        }
        
        if ($this->form_validation->run() == FALSE)
        {
            $this->index();
        }
    }
    
    function insert_chat()
    {
        $this->form_validation->set_rules('chat_name', 'Name', 'required');
        $this->form_validation->set_rules('chat_body', 'Content', 'required');
        $this->form_validation->set_rules('chat_link', 'Link', 'xss_clean');
        
        if($this->form_validation->run() == TRUE)
        {
            $this->Chat->say();
        
            $this->index();
        }
        else
        {
            $this->load->view('contact_view',$data);
        }
    }
}

the problem is, after a user inserts and email or chat entry, the URI will appear as

site/contact/insert_email or site/contact/insert_comment

which is quite unsightly...

Any advice on how to make it look like ' site/contact ' ? Or is this how it should look...

using redirect('contact') will make the URI look correct, but it won't work because the validation error variables won't get passed on...

also because of this, I have to call my chat db query again in the insert_email function or the query will not exist..

Thank you for your time!
#2

[eluser]akkumaru[/eluser]
,,do you mean validation error messages?

redirecting after DB CRUD is what I choose,
about the error message, You can save it temporarily with
Code:
$this->session->set_flashdata('contact_error',"Your Error Message Here");
#3

[eluser]kevinprince[/eluser]
The URL will always be the function your calling.

So when the form posts to Contact/insert_chat it is there where the error occurs, as such when you call a view your still executing in that function.

There are 2 ways if you really dont like this:

1) Put the refill of the form into the session global, redirect, have handling for said session data in your display create chat function which calls the form

2) Hack CI Routing (BAD)




Theme © iAndrew 2016 - Forum software by © MyBB