Part of the EllisLab Network
   
 
Form Validation
Posted: 08 February 2010 10:13 PM   [ Ignore ]  
Summer Student
Total Posts:  5
Joined  02-08-2010

Hey, I am having an issue with validating my form, for some reason the form_validation library is not loading…

this is my Email Controller:

<?php

class Email extends Controller
{
            
function __construct(){
                parent
::Controller();
            
}
            
function index()
            
{
            $this
->load->view('contact');
            
$this->load->library('form_validation');
            
}
            
            
function send()
            
{
    
                
                
//Field name error message
                
$this->load->form_validation->set_rules('name''Name''trim|required');
                
$this->load->form_validation->set_rules('message''Message''required');
                
$this->load->form_validation->set_rules('email''Email Address''trim|required|valid_email');
                
                if(
$this->form_validation->run()==FALSE)
                
{
                $this
->load->view('contact');
                
}
                
else
                
{
                    
//validation has passed
                    
$name$this->input->post('name');
                    
$email$this->input->post('email');
                    
                    
                    
$this->load->library('email');
                    
$this->email->set_newline("\r\n");
                    
                    
$this->email->from('parabolic151@gmail.com'$email);
                    
$this->email->to('pjahk@pdbmedia.com');
                    
$this->email->subject($subject);
                    
$this->email->message($message);
                    
                    
$path $this->config->item('server_root');
                    
                    
                    if(
$this->email->send())
                    
{
                        
echo'your message has been sent yoooo!';
                    
}
                    
else
                    
{
                        show_error
($this->email->print_debugger());
                    
}
                }
                
                
            }


This is the error message that comes up when i try to use the form..

A PHP Error was encountered

Severity: Notice

Message: Undefined property: CI_Loader::$form_validation

Filename: controllers/email.php

Line Number: 24


if you want to see MY SITE it is the contact section I am having issues with…

Profile
 
 
Posted: 08 February 2010 10:18 PM   [ Ignore ]   [ # 1 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  342
Joined  12-16-2009

what code is in the line 24??

 Signature 

“Anything executable is testable”- debug

Profile
 
 
Posted: 08 February 2010 10:30 PM   [ Ignore ]   [ # 2 ]  
Summer Student
Total Posts:  5
Joined  02-08-2010

it is referring to :  $this->load->form_validation->set_rules(‘name’, ‘Name’, ‘trim|required’);

Profile
 
 
Posted: 08 February 2010 10:40 PM   [ Ignore ]   [ # 3 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  342
Joined  12-16-2009
parabolic151 - 09 February 2010 03:30 AM

it is referring to :  $this->load->form_validation->set_rules(‘name’, ‘Name’, ‘trim|required’);


can you try this:

$this->form_validation->set_rules('name''Name''required'); 

and yo check this thread… http://codeigniter.com/forums/viewthread/47592/

 Signature 

“Anything executable is testable”- debug

Profile
 
 
Posted: 08 February 2010 11:03 PM   [ Ignore ]   [ # 4 ]  
Research Assistant
RankRankRank
Total Posts:  663
Joined  08-26-2006

You load the library only in the method index(), put the call into the constructor or the send method.

 Signature 

Die Wirklichkeit ist das, was übrig bleibt, wenn man aufgehört hat, daran zu glauben.

Profile
 
 
Posted: 09 February 2010 12:39 AM   [ Ignore ]   [ # 5 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  650
Joined  11-18-2008

You load the library only in the method index(), put the call into the constructor or the send method.

and, once you have moved the loading of the library to the constructor, make sure you change your rule setting to:

$this->form_validation->set_rules('name''Name''required'); 

instead of:

$this->load->form_validation->set_rules('name''Name''required'); 

(remove the “load” section)

 Signature 

Quality Coder | Looking for work? | Logo by InsiteFX

Profile
 
 
Posted: 09 February 2010 02:19 AM   [ Ignore ]   [ # 6 ]  
Summer Student
Total Posts:  5
Joined  02-08-2010

ok thanks, that fixed the problem, now a bunch of other Errors show up. But hey, the validation works now. Thank you for your Help!!

Profile
 
 
Posted: 09 February 2010 02:30 AM   [ Ignore ]   [ # 7 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  650
Joined  11-18-2008

what other errors?

 Signature 

Quality Coder | Looking for work? | Logo by InsiteFX

Profile
 
 
Posted: 09 February 2010 03:44 AM   [ Ignore ]   [ # 8 ]  
Summer Student
Total Posts:  5
Joined  02-08-2010

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: subject

Filename: controllers/email.php

Line Number: 46

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: message

Filename: controllers/email.php

Line Number: 47

A PHP Error was encountered

Severity: Warning

Message: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.googlemail.com:465 (Connection timed out)

Filename: libraries/Email.php

Line Number: 1652

A PHP Error was encountered

Severity: Warning

Message: fwrite() expects parameter 1 to be resource, boolean given

Filename: libraries/Email.php

Line Number: 1795

A PHP Error was encountered

Severity: Warning

Message: fgets() expects parameter 1 to be resource, boolean given

Filename: libraries/Email.php

Line Number: 1818

A PHP Error was encountered

Severity: Warning

Message: fwrite() expects parameter 1 to be resource, boolean given

Filename: libraries/Email.php

Line Number: 1795

A PHP Error was encountered

Severity: Warning

Message: fgets() expects parameter 1 to be resource, boolean given

Filename: libraries/Email.php

Line Number: 1818

A PHP Error was encountered

Severity: Warning

Message: fwrite() expects parameter 1 to be resource, boolean given

Filename: libraries/Email.php

Line Number: 1795

A PHP Error was encountered

Severity: Warning

Message: fgets() expects parameter 1 to be resource, boolean given

Filename: libraries/Email.php

Line Number: 1818

A PHP Error was encountered

Severity: Warning

Message: fwrite() expects parameter 1 to be resource, boolean given

Filename: libraries/Email.php

Line Number: 1795

A PHP Error was encountered

Severity: Warning

Message: fgets() expects parameter 1 to be resource, boolean given

Filename: libraries/Email.php

Line Number: 1818

A PHP Error was encountered

Severity: Warning

Message: fwrite() expects parameter 1 to be resource, boolean given

Filename: libraries/Email.php

Line Number: 1795

A PHP Error was encountered

Severity: Warning

Message: fwrite() expects parameter 1 to be resource, boolean given

Filename: libraries/Email.php

Line Number: 1795

A PHP Error was encountered

Severity: Warning

Message: fgets() expects parameter 1 to be resource, boolean given

Filename: libraries/Email.php

Line Number: 1818

A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /customers/pdbmedia.com/pdbmedia.com/httpd.www/system/libraries/Exceptions.php:166)

Filename: codeigniter/Common.php

Line Number: 356

An Error Was Encountered
The following SMTP error was encountered: 110 Connection timed out
Unable to send data: AUTH LOGIN
Failed to send AUTH LOGIN command. Error:
Unable to send data: MAIL FROM:

Profile
 
 
Posted: 09 February 2010 03:45 AM   [ Ignore ]   [ # 9 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  342
Joined  12-16-2009

can you post the code that pertains those error??

 Signature 

“Anything executable is testable”- debug

Profile
 
 
Posted: 09 February 2010 06:20 AM   [ Ignore ]   [ # 10 ]  
Summer Student
Total Posts:  5
Joined  02-08-2010

the library/email.php is the same as what comes with code igniter. i did not mess with that at all here is the updated code for controler/email.php::

<?php


/**
 * sends Email with Gmail
 */

class Email extends Controller
{
            
function __construct(){
                parent
::Controller();
                
$this->load->library('form_validation');
                
            
}
            
function index()
            
{
            $data[
'title'='CONTACT';
            
$this->load->view('contact');
            
}
            
            
function send()
            
{
    
                
                
//Field name error message
                
$this->form_validation->set_rules('name''Name''trim|required');
                
$this->form_validation->set_rules('message''Message''required');
                
$this->form_validation->set_rules('email''Email Address''trim|required|valid_email');
                
                if(
$this->form_validation->run()==FALSE)
                
{
                $this
->load->view('contact');
                
}
                
else
                
{
                    
//validation has passed
                    
$name$this->input->post('name');
                    
$email$this->input->post('email');
                    
                    
                    
$this->load->library('email');
                    
$this->email->set_newline("\r\n");
                    
                    
$this->email->from('parabolic151@gmail.com'$email);
                    
$this->email->to('patrick@pdbmedia.com');
                    
$this->email->subject($subject);
                    
$this->email->message($message);
                    
                    
$path $this->config->item('server_root');
                    
                    
                    if(
$this->email->send())
                    
{
                        
echo'your message has been sent';
                    
}
                    
else
                    
{
                        show_error
($this->email->print_debugger());
                    
}
                }
                
                
            }

those are the only 2 files the errors pertain to…

Profile
 
 
Posted: 09 February 2010 06:43 AM   [ Ignore ]   [ # 11 ]  
Research Assistant
RankRankRank
Total Posts:  663
Joined  08-26-2006

The subject and message are not set.

Edit: ... the variables

 Signature 

Die Wirklichkeit ist das, was übrig bleibt, wenn man aufgehört hat, daran zu glauben.

Profile