Welcome Guest, Not a member yet? Register   Sign In
simple error question
#7

[eluser]RyanH[/eluser]
[quote author="Seppo" date="1201166632"]Just checking a possible error...

Can you copy the controller code?[/quote]Sure, here it is:
Code:
<?php

class Contact extends Controller{
    
    function Contact()
    {
        parent::Controller();
    }
    
    function index()
    {
        // Load the helpers for URLs and forms
        $this->load->helper('url');
        $this->load->helper('form');
        
        // Load the library for validation
        $this->load->library('validation');    
        $this->load->library('email');    
        
        // Set page information and load the view file
        $data['title'] = "Contact";
        $this->load->view('contact_view', $data);
        
        // Set the validation rules
        $rules['name'] = "required|trim";
        $rules['email'] = "required|trim";
        $rules['subject'] = "";
        $rules['message'] = "required|trim";
        $this->validation->set_rules($rules);
        
        // Set the fields for all of the input fields in case someone enters something incorrectly
        $fields['name'] = "Name";
        $fields['email'] = "Email";
        $fields['subject'] = "Subject";
        $fields['message'] = "Message";
        $this->validation->set_fields($fields);
        
        // Run the validation and if it's not successful, return them to the registration page
        // If the validation is successful, send the email
        if($this->validation->run() == FALSE)
        {
            $this->load->view('contact_view');
        } else {
            $this->email->from($this->validation->email, $this->validation->name);
            $this->email->to('[email protected]');
            $this->email->subject($this->input->post('subject'));
            $this->email->message($this->validation->message);
            
            $this->email->send();
            
            echo $this->email->print_debugger();
        }    
    }
}
In case you want to see it, here's the view file (this isn't the final HTML, just enough to test the functionality):
Code:
<html>
<head>
    <title><?=$title?></title>

Contact form:

<?=form_open('contact'); ?>

Name: <input type="text" name="name" value="<?=$this->validation->name;?>" /> <?=$this->validation->name_error;?>
<br />
Email: &lt;input type="text" name="email" value="&lt;?=$this-&gt;validation->email;?&gt;" /> &lt;?=$this->validation->email_error;?&gt;

<br />
Subject: <select name="subject">
         <option selected value="General Inquiry">General Inquiry</option>
         <option value="Bug report">Bug Report</option>
         <option value="Other">Other</option>
         </select>
<br />
Message: &lt;textarea name="message" rows="10" cols="40"&gt;&lt;?=$this->validation->message;?&gt;&lt;/textarea&gt; &lt;?=$this->validation->message_error;?&gt;
<br />
&lt;input type="submit" name="submit" value="Send" /&gt;
<br /><br />
        
&lt;/body&gt;

&lt;/html&gt;
I should also note that the undefined property error is being generated on all of the fields (name, email, subject and message).

Thanks for your help! Smile


Messages In This Thread
simple error question - by El Forum - 01-15-2008, 08:56 AM
simple error question - by El Forum - 01-15-2008, 10:38 AM
simple error question - by El Forum - 01-23-2008, 07:20 PM
simple error question - by El Forum - 01-23-2008, 09:10 PM
simple error question - by El Forum - 01-23-2008, 09:21 PM
simple error question - by El Forum - 01-23-2008, 09:23 PM
simple error question - by El Forum - 01-23-2008, 09:27 PM
simple error question - by El Forum - 01-23-2008, 09:31 PM
simple error question - by El Forum - 01-23-2008, 09:33 PM
simple error question - by El Forum - 01-23-2008, 09:39 PM
simple error question - by El Forum - 01-23-2008, 09:49 PM



Theme © iAndrew 2016 - Forum software by © MyBB