CodeIgniter Forums
Organizing the Site! - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Organizing the Site! (/showthread.php?tid=8429)

Pages: 1 2


Organizing the Site! - El Forum - 05-17-2008

[eluser]Drew Barontini[/eluser]
Code:
class Contact extends Controller {
    
    function index() {
        
        // Validations
        $this->load->library('validation');
        $rules['name'] = "required";
        $rules['email'] = "required|valid_email";
        $this->validation->set_rules($rules);
        
          // Input and textarea field attributes
        $data['name'] = array('name' => 'name', 'id' => 'name');
        $data['email'] = array('name' => 'email', 'id' => 'email');
        $data['comments'] = array('name' => 'comments', 'id' => 'comments', 'rows' => 3, 'cols' => 40);

        // Checkbox attributes
        $data['graphic'] = array('name' => 'services[]', 'id' => 'graphic', 'value' => 'Graphic Design', 'checked' => FALSE);
        $data['web'] = array('name' => 'services[]', 'id' => 'web','value' => 'Web Design/Development', 'checked' => FALSE);
        $data['myspace'] = array('name' => 'services[]', 'id' => 'myspace','value' => 'Myspace Design', 'checked' => FALSE);
        $data['cms'] = array('name' => 'services[]', 'id' => 'cms','value' => 'CMS', 'checked' => FALSE);

        if ($this->validation->run() == FALSE) {
            
            $this->load->view('contact/contact_view', $data);
    
        } else {
            
            // Get POST data
            $name = $this->input->post('name');
            $email = $this->input->post('email');
            $comments = $this->input->post('comments');
            $services = "";

            foreach($this->input->post('services') as $value) {

                $services .= "$value\n";

            }

            $message = $name . " would like the following   services:\n\n" . $services . "\n\n". $name ." also said:\n" . $comments;

            // Set our email fields
            $this->email->from($email, $name);
            $this->email->to('[email protected]');
            $this->email->subject('Your services are requested!');
            $this->email->message($message);
            $this->email->send();

            //load our view file
            $this->load->view('contact/contact_success');

        }
    
    }
        
}