Welcome Guest, Not a member yet? Register   Sign In
Email Sending Not Working With Validation
#1

[eluser]razerone[/eluser]
Hi I just thought would add my email code to validation when I did would validation world not work with email set up

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

class Contactus extends MX_Controller {

public function index() {

  $this->load->library('form_validation');

  $this->form_validation->set_rules('name', 'Name', 'required');
  $this->form_validation->set_rules('email', 'Email', 'required');
  $this->form_validation->set_rules('website', 'Website', 'required');
  $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('header');
   $this->load->view('contactus');
   $this->load->view('footer');
  }
  else
  {
   $this->load->view('header');
   $this->load->view('confirmation');
   $this->load->view('footer');
  }

}

public function confirmation() {
  $this->load->library('email');
  $this->email->from($this->input->post('email'), $this->input->post('name'));
   $this->email->to('[email protected]');
  $this->email->subject($this->input->post('email'));
  $this->email->subject($this->input->post('username'));
  $this->email->subject($this->input->post('website'));
  $this->email->subject($this->input->post('subject'));
  $this->email->message($this->input->post('message'));
  if($this->email->send()) {
  
   $this->load->view('header');
   $this->load->view('confirmation');
   $this->load->view('footer');
  }
  else {

   show_error($this->email->print_debugger());

  }
}
}

Code:
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
  <div id="contactus">
   <h1>Contact Us</h1>
   <hr>
   &lt;form role="form" method="post" acti echo base_url('contactus/confirmation');?&gt;"&gt;
    <div class="form-group">
     &lt;input type="text" class="form-control" placeholder="Your Name" name="name" &gt;
     &lt;?php echo form_error('name', '<div class="alert alert-danger contact-warning">', '</div>'); ?&gt;
    </div>
    <div class="form-group">
     &lt;input type="text" class="form-control" placeholder="Your Email" name="email"&gt;
     &lt;?php echo form_error('email', '<div class="alert alert-danger contact-warning">', '</div>'); ?&gt;
    </div>
    <div class="form-group">
     &lt;input type="text" class="form-control" placeholder="Your Website Address" name="website"&gt;
     &lt;?php echo form_error('website', '<div class="alert alert-danger contact-warning">', '</div>'); ?&gt;
    </div>
    <div class="form-group">
     &lt;input type="text" class="form-control" placeholder="Your Subject" name="subject"&gt;
     &lt;?php echo form_error('subject', '<div class="alert alert-danger contact-warning">', '</div>'); ?&gt;
    </div>
    <div class="form-group">
     &lt;textarea class="form-control" rows="10" placeholder="Please Enter Your Message" name="message"&gt;&lt;/textarea>
     &lt;?php echo form_error('message', '<div class="alert alert-danger contact-warning">', '</div>'); ?&gt;
    </div>
    <hr>
    <div class="form-group">
     <button type="reset" class="btn btn-danger">Clear Form</button>
     <button type="submit" class="btn btn-success">Send Message</button>
    </div>
   &lt;/form&gt;
  </div>
</div>
</div>

What have I done wrong?
#2

[eluser]noideawhattotypehere[/eluser]
How do you want to validate when your form points to method without any validation?
#3

[eluser]razerone[/eluser]
[quote author="noideawhattotypehere" date="1383228546"]How do you want to validate when your form points to method without any validation?[/quote]

Not to sure what you mean.

I got validation to work with out my contact function. But when I add my contact stuff validation would not work

http://www.development2.carrarawebsiteso.../contactus

Click send and you will see validation.


This is what I am trying to add on controller

Code:
$this->email->from($this->input->post('email'), $this->input->post('name'));
  $this->email->to('[email protected]');

  $this->email->subject($this->input->post('email'));
  $this->email->subject($this->input->post('username'));
  $this->email->subject($this->input->post('website'));
  $this->email->subject($this->input->post('subject'));
  $this->email->message($this->input->post('message'));

  if($this->email->send()) {
  
   $this->load->view('header');
   $this->load->view('confirmation');
   $this->load->view('footer');
  }
  else {

   show_error($this->email->print_debugger());

  }

Code:
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Contactus extends MX_Controller {

public function index() {
  $this->load->helper('form');

  $this->load->library('form_validation');

  $this->form_validation->set_rules('name', 'Name', 'required');
  $this->form_validation->set_rules('email', 'Email', 'required');
  $this->form_validation->set_rules('website', 'Website', 'required');
  $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('header');
   $this->load->view('contactus');
   $this->load->view('footer');
  }
  else
  {
   $this->load->view('header');
   $this->load->view('confirmation');
   $this->load->view('footer');
  }

}
}

not to sure also what to put as value been trying to under stand userguide
#4

[eluser]razerone[/eluser]
I am slowly working it out now fixing my errors.

Good way I found is this

Code:
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
  <div id="contactus">
   <h1>Contact Us</h1>
   <hr>
   &lt;?php

    $this->load->helper('form');

    echo form_open('contactus/confirmation');

   ?&gt;

    <div class="form-group">

     &lt;?php

      $data = array(

       "name" => "fullname",
       "id" => "fullname",
       "class" => "form-control",
       "value" => "",
       "placeholder" => "Name"

      );

      echo form_input($data);

     ?&gt;

    </div>

    &lt;?php echo form_close();?&gt;

  
  </div>
</div>
</div>




Theme © iAndrew 2016 - Forum software by © MyBB