首页 > 解决方案 > 在codeigniter中提交表单后查看同一页面

问题描述

嗨,我正在使用表单提交,但我希望即使在提交表单后我也想显示联系页面。我不想查看错误或成功页面

这是我的控制器:

public function validate()
    {
        $name    = $this->input->post("name");
        $email   =$this->input->post("email");
        $captcha   =$this->input->post("captcha");
        $message =$this->input->post("message");
        $captcha_code     =$this->session->userdata("captcha_code");

        if($captcha == $captcha_code){
            $this->load->library("PHPMailer_Library");
        $objMail = $this->phpmailer_library->load();


        $mail = new PHPMailer(true);                              
        try {

        $mail->SMTPDebug = 2;                               
        $mail->isSMTP();                                      
        $mail->Host = 'smtp.gmail.com';  
        $mail->SMTPAuth = true;                               
        $mail->Username = 'proxyemu19@gmail.com';                 
        $mail->Password = '****';                           
        $mail->SMTPSecure = 'tls';                            
        $mail->Port = 587;   
        $mail->SMTPOptions = array(
        'ssl' => array(
            'verify_peer' => false,
            'verify_peer_name' => false,
            'allow_self_signed' => true
            )
        );                                 

        $mail->setFrom('proxyemu19@gmail.com');
        $mail->addAddress('cugurel7@gmail.com');     
        $mail->isHTML(true);                                 
        $mail->Subject = 'Ziyaretçi Form Mesajı';
        $mail->Body    ="Ziyaretçi ismi: ". $name."<br>Ziyaretçi mail adresi ".$email."<br> Ziyaretçi e-posta: ".$message;
        $mail->AltBody = strip_tags($message);

        $mail->send();

        echo 'Message has been sent';
        } catch (Exception $e) 
        {
            echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
        }
        }else{
            echo "Doğrulama kodu yanlıştır";
        }


    }

你能帮我吗,我该怎么做。我的联系页面 yerel/yansayfa/contact。我想在提交后显示这个。

谢谢!!!

标签: formscodeigniter

解决方案


您可以redirect()在控制器上使用或制作功能,并在完成进度后调用它们

例如:

public function validate(){
.
.
.

if($mail->send();){
    $this->next_function();
}else{
    echo 'ops';
}
.
.
.
}

public function next_function(){
    $this->load->view('name');
}

推荐阅读