Part of the EllisLab Network
   
 
Form Validation and password change?
Posted: 14 March 2009 04:03 PM   [ Ignore ]  
Summer Student
Total Posts:  24
Joined  07-28-2008

Hi Folks,

I’ve liked the new form validation class very much, but with the time i stumble over more and more problems.

I’m facing currently a small problem and curious about if anyone has a good solution.

Imagine a form displaying the users profile which allows to change the password.

so you have the following 3 fields (addiotional to all the other fields of the profile):
Current password
New password
New password (repeat)

how would you setup the rules for that?
I need to tell, the new password should only be set IF the user enteres something into it. As long as the user lets “current password” empty, nothing happens.

Any ideas?

Profile
 
 
Posted: 14 March 2009 04:07 PM   [ Ignore ]   [ # 1 ]  
Grad Student
Avatar
Rank
Total Posts:  36
Joined  07-22-2007

I’m guessing you need a simple IF statement:

if(isset($_POST['password']) AND isset($_POST['password2']))
{
    
// add validation rules
}

// The rest of the code...
 Signature 

I am sorry if my english is ugly, it’s a foreign language for me anyway!

Profile
 
 
Posted: 14 March 2009 04:10 PM   [ Ignore ]   [ # 2 ]  
Summer Student
Total Posts:  24
Joined  07-28-2008

doh….

ok not exactly that but the idea…. grin

I never thought of the possibility to adding rules depending on the input situation.
I always assumed i set my rules and have to live with it… i don’t know if this is the best solution but it offers great possibilities to me .-)

Thx for the hint….

Again a proof that sometimes you don’t see the forest due to too many trees.

Profile
 
 
Posted: 14 March 2009 04:36 PM   [ Ignore ]   [ # 3 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  2052
Joined  06-04-2008

Well, you could also have normal validation rules such as min_length[x].

And you should probably refer to $this->input->post(‘password1’) rather than $_POST directly.

Profile
 
 
Posted: 14 March 2009 05:07 PM   [ Ignore ]   [ # 4 ]  
Summer Student
Total Posts:  24
Joined  07-28-2008

Hi Jedd,

i think with normal rules you can’t do that.

Sure i didn’t used post directly.

heres a snippet what i currently doing (see the addtional required flag)

$this->form_validation->set_rules('pass1', 'Neues Passwort', 'trim|min_length[6]|max_length[20]|xss_clean');
            
$this->form_validation->set_rules('pass2', 'Neues Passwort (Wiederholung)', 'trim|min_length[6]|max_length[20]|matches[pass1]|xss_clean');

            
$this->form_validation->set_rules('email', 'E-Mail', 'trim|valid_email|callback_check_email|xss_clean');
        
}

        
//there is a special situation!!!
        //if the user enters a new password there has to be some different rules
        
if ( $this->input->post("pass1") ){
            $this
->form_validation->set_rules('pass', 'Aktuelles Passwort', 'trim|required|min_length[6]|max_length[20]|callback_check_password|xss_clean');
            
$this->form_validation->set_rules('pass2', 'Neues Passwort (Wiederholung)', 'trim|required|min_length[6]|max_length[20]|matches[pass1]|xss_clean');
        
}
Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 819, on March 11, 2010 11:15 AM
Total Registered Members: 120493 Total Logged-in Users: 41
Total Topics: 126564 Total Anonymous Users: 7
Total Replies: 665426 Total Guests: 362
Total Posts: 791990    
Members ( View Memberlist )