1

No código abaixo, após o envio do formulário via e-mail, é carregado a mesma view. Ao invés disso, preciso que seja direcionado para uma outra view. (agradecimento por exemplo)

Abaixo segue o código:

public function duvidas_e_contatos() {
    $this->load->helper('form');
    $this->load->library('form_validation');
    // REGRA DE VALIDAÇÃO
    $this->form_validation->set_rules('firstname', 'Nome', 'trim|required');
    $this->form_validation->set_rules('lastname', 'Sobrenome', 'trim|required');
    $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
    $this->form_validation->set_rules('mobilephone', 'Celular', 'trim|required');
    $this->form_validation->set_rules('country', 'País', 'trim|required');
    $this->form_validation->set_rules('subject', 'Motivo do Contato', 'trim|required');
    $this->form_validation->set_rules('coment', 'Mensagem', 'trim|required');
    $this->form_validation->set_error_delimiters('<small class="text-danger">', '</small>');

    $infoPage['form_error']     = validation_errors();
        $infoPage['title']          = '';
        $infoPage['description']    = '';
        $infoPage['keywords']       = '';
        $infoPage['canonical']      = '';
        $infoPage['autor']          = '';
        $infoPage['webmaster']      = '';
        $infoPage['credits']        = ''

    if ($this->form_validation->run() == FALSE) {
        $infoPage['form_error']     = validation_errors();
        $infoPage['title']          = '';
        $infoPage['description']    = '';
        $infoPage['keywords']       = '';
        $infoPage['canonical']      = '';
        $infoPage['autor']          = '';
        $infoPage['webmaster']      = '';
        $infoPage['credits']        = '';

        $this->load->view('duvidas_e_contatos', $infoPage);

    } else {
        $formrequest = $this->input->post();
        date_default_timezone_set('America/Sao_Paulo');
        $this->load->library('email');
        $this->email->set_newline("\r\n");
        $this->email->initialize();

        $formrequest = $this->input->post();

        $subject = $formrequest['subject'];

        $mensagem_firstname     = $formrequest['firstname'];
        $mensagem_lastname      = $formrequest['lastname'];
        $mensagem_email         = $formrequest['email'];
        $mensagem_mobilephone   = $formrequest['mobilephone'];
        $mensagem_country       = $formrequest['country'];
        $mensagem_subject       = $formrequest['subject'];
        $mensagem_coment        = nl2br($formrequest['coment']);

        $message = "html";

        $body = $message;

        $result = $this->email
                ->from('')
                ->reply_to($formrequest['email'], $formrequest['firstname'])
                ->to('')
                ->cc('')
                ->bcc($formrequest['email'])
                ->subject($subject)
                ->message($body)
                ->send();

        $infoPage['firstname']      = $formrequest['firstname'];
        $infoPage['lastname']       = $formrequest['lastname'];
        $infoPage['email']          = $formrequest['email'];
        $infoPage['mobilephone']    = $formrequest['mobilephone'];
        $infoPage['country']        = $formrequest['country'];
        $infoPage['subject']        = $formrequest['subject'];
        $infoPage['coment']         = $formrequest['coment'];

        $infoPage['title']          = 'Confirmação de Contato';
        $infoPage['description']    = '';
        $infoPage['keywords']       = '';
        $infoPage['canonical']      = '';
        $infoPage['subtitle']       = 'Sua mensagem foi recebida!';
        $infoPage['autor']          = '';
        $infoPage['webmaster']      = '';
        $infoPage['credits']        = '';

        $this->load->view('mensagem_enviada', $infoPage);
    }
}

1 Resposta 1

3

Uma forma legal seria alterar aonde chama:

$this->load->view('mensagem_enviada', $infoPage);

E utilizar desta forma:

if ($result)
{
     redirect('/aondequiser', 'refresh');
}

Lembrando que para isto você irá precisar do helper url carregado:

$this->load->helper('url');
2
  • Muitíssimo obrigado @otto acabou sendo exatamente assim que resolvi esse problema. Acabei encontrando o redirect na documentação -> [link]codeigniter.com/user_guide/helpers/…. 23/08/2017 às 1:35
  • @WillianSilva se te ajudou marque como resolvida a pergunta.
    – Otto
    23/08/2017 às 11:25

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .