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

[eluser]Unknown[/eluser]
Hello Everyone!!

Im trying to figure out an error Im getting with validation class.

I have 2 views

register and register process

im doing some validation in register process that redirects ur back to register.

for some reason, when processing errors, since errors are instaniated at regprocess, when you come to the main register, you get this error
Quote:Message: Undefined property: CI_Validation::$first_name_error

is there a way I can set this ?

Any help would help Smile

Thanks
#2

[eluser]eggshape[/eluser]
In your view do you have code that looks like this:

Code:
echo $this->validation->first_name_error;

if you do and you have no error for $first_name you will get that message.

change your view to:

Code:
if (isset($this->validation->first_name_error)) echo $this->validation->first_name_error;
#3

[eluser]RyanH[/eluser]
I'm having a similar issue. I have a registration page that has validation and it's something like this:
Code:
<input type="text" name="name" value="<?=$this->validation->name;?>" /> <?=$this->validation->name_error;?>
On my registration page this works fine. No errors, it's all submitted and everything works fine. However I created a simple contact page with essentially the same code (instead of being submitted to a database it sends an email instead) and I get the following error:
PHP Error Wrote:A PHP Error was encountered

Severity: Notice

Message: Undefined property: CI_Validation::$name

Filename: views/someview.php
As with the registration page that works just fine, the rules are set as are the fields. Why would this work on one page and not the other?
#4

[eluser]Seppo[/eluser]
Are you using PHP 4, and do you have Validation in autoload libraries?
#5

[eluser]RyanH[/eluser]
[quote author="Seppo" date="1201165838"]Are you using PHP 4, and do you have Validation in autoload libraries?[/quote]I'm using PHP 5 and the validation library is not auto loaded. However why would this work just fine with no problems on my registration page but not on my contact page when everything is setup the same?
#6

[eluser]Seppo[/eluser]
Just checking a possible error...

Can you copy the controller code?
#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
#8

[eluser]Seppo[/eluser]
You are loading the view before setting the validation fields/rules :S
And then calling it again...
#9

[eluser]RyanH[/eluser]
I don't understand. Near the top I'm loading the view file. I'm only loading it again when the form is submitted and if the validation fails. Is this incorrect?
#10

[eluser]Seppo[/eluser]
The first time should be after setting the fields and the rules... That´s why it can´t find the fields errors: they aren´t setted.
The second time is also calling the view, cause it is failing the validation...
A simplier way to do it

Code:
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";
        
        // 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
        // If the validation is successful, send the email
        if($this->validation->run() == TRUE)
        {
            $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();
        } else {
             // and if it's not successful (or the form is not sent), return them to the registration page
            $this->load->view('contact_view', $data);
        }
    }




Theme © iAndrew 2016 - Forum software by © MyBB