Welcome Guest, Not a member yet? Register   Sign In
Codeigniter contact form - newbie in need of help
#1

[eluser]runtaylor[/eluser]
Link to old thread http://ellislab.com/forums/viewthread/233129
I'm brand new to code igniter and learning it as I'm working on this website
Basically I'm trying to get a contact form going but it's proving to be VERY difficult for some reason

I have the form displaying on my site and everything but when I submit it it goes to a blank page and doesn't send the email or go to success_view like it should

the page is: http://www.vancouverticket.com/contact then it goes to contact/emailsender instead of running the email sender function

I'm sure I'm missing something silly but please help me out
I got the original code from: https://github.com/furiston/codeigniter-...ll/1/files and modified the code a bit

here is the controller:
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Contact extends CI_Controller{
    function __construct() {
        parent::__construct();
    }
    
    function index(){
      
// load email and form helpers ** you can autoload them from config/autoload.php
$this->load->helper('email');
$this->load->helper('form');

  
   $this->load->model('Testimonials_model');
  $navigation_data['testimonial'] = $this->Testimonials_model->show_random();
  
  $header_data['page_title']   = 'Contact Vancouver Ticket';
  $navigation_data['active_nav']  = 'contact';
  
  $this->load->view('templates/header', $header_data);
  $this->load->view('templates/left_navigation_view', $navigation_data);
  $this->load->view('contact_view');
  $this->load->view('templates/footer');
    }

    function emailsender(){
// load form validation class
     $this->load->library('form_validation');

// set form validation rules
     $this->form_validation->set_rules('sender_name', 'From', 'required');
$this->form_validation->set_rules('sender_email', 'Email', 'required|valid_email');
$this->form_validation->set_rules('subject', 'Subject', 'required');
$this->form_validation->set_rules('message', 'Message', 'required');

     if ($this->form_validation->run() == FALSE)
{
  $this->load->view('contact_view');
}
else {
  // you can also load email library here
  // $this->load->library('email');

  // set email data
      $this->email->from($this->input->post('sender_email'), $this->input->post('sender_name'));
      $this->email->to('[email protected]');
      $this->email->reply_to($this->input->post('sender_email'), $this->input->post('sender_name'));
      $this->email->subject($this->input->post('subject'));
      $this->email->message($this->input->post('message'));
      $this->email->send();

  // create a view named "succes_view" and load it at the end
      $this->load->view('success_view');
}    
    }
}
?>


and the view

Code:
<head>
<meta charset="utf-8">
<title>Contact Us</title>
<meta name="description" c Vancouver Ticket and Tour Service at [email protected]">

<meta name="copyright" c ? 2012 Vancouver Ticket">
<meta name="designer" c Plantzos , Jaryn Bailey & Taylor Harris">
<meta name="robots" c follow">
<meta name="googlebot" c follow">
<meta http-equiv="content-language" c>



<style type="text/css">

.row:before, .row:after {
  display: none;
  content: "";

}
.row { display: block;
padding-right:-50px;}



</style>
</head>
  <div class="span9" >
<div class="well" >
&lt;?php echo form_open('contact/emailsender'); ?&gt;
<h1>Send your message:</h1>
<table>
  <tr>
   <td>&lt;?php echo form_input('sender_name', 'From');?&gt;&lt;?php echo form_error('sender_name'); ?&gt;</td>    
  </tr>
  <tr>
   <td>&lt;?php echo form_input('sender_email', 'Email');?&gt;&lt;?php echo form_error('sender_email'); ?&gt;</td>
  </tr>
  <tr>
   <td>&lt;?php echo form_input('subject', 'Subject');?&gt;&lt;?php echo form_error('subject'); ?&gt;</td>
  </tr>
  <tr>
   <td>&lt;?php echo form_textarea('message', 'Message');?&gt;&lt;?php echo form_error('message'); ?&gt;</td>
  </tr>
  <tr>
   <td>&lt;?php echo form_submit('submit', 'Send');?&gt;</td>
  </tr>
</table>
&lt;?php echo form_close();?&gt;
[removed]
  $(function() {
      $('input[type=text], textarea').focus(function() {
       $(this).val('');
    });
   });
[removed]
</div></div>
#2

[eluser]runtaylor[/eluser]
bump. Still stuck on this
#3

[eluser]Otemu[/eluser]
Hi,

Break it down it steps, first just try to load the view within the emailsender() function with no other code confirm that works.

Then Try it with just the form validation and see if that works and sends to the success page, there is a chance it could be failing on the fallback ''required|valid_email" as you have no valid_email function.

Then try the email class on its own see if that is sending email.

This help you narrow down what is actually causing the issue, then after that you should be able to put it all back together.
#4

[eluser]InsiteFX[/eluser]
Check to see if it is sending the email, also where is your email configuration?
Code:
if ( ! $this->email->send())
{
     // Generate error
}
#5

[eluser]runtaylor[/eluser]
It is not sending the email
the view is loading here fine http://www.vancouverticket.com/contact

my config is here:
Code:
$route['contact']       = 'pages/contact';

https://github.com/furiston/codeigniter-...ll/1/files is where i originally got the files and I made the changes as suggested by one of the users. There was no specific config file for the emailer so I just wrote the route so the view would display properly.

Sorry if I have missed something I am quite new to this
#6

[eluser]Aken[/eluser]
First, blank page usually means PHP error, but error displaying is turned off. Google around for "PHP blank page" and solve that problem.

Second, the Email library is not a helper, it's a library. So it's being loaded incorrectly.

Third, there's really zero need for a second method to control receiving the form submission. Everything can be done in the index() method.

Fourth, the route is only for if you want the URL "example.com/pages/contact". Otherwise "example.com/contact" should work fine.

Fifth, read the user guide if you're new. Learn for yourself, because not all code out there is good and should be used / followed / learnt from (as exampled here...).




Theme © iAndrew 2016 - Forum software by © MyBB