tags:

views:

15

answers:

1

Hi all,

I got two simple input text fields in a HTML form:

<input type="text" name="data[User][name]" id="data[User][name]">   
<input type="text" name="data[User][pswd]" id="data[User][pswd]">    

The scripts for the Controller's action that captured the data is as follows:

 function register(){ 
          $temp = $this->data;                       
          if(strlen($temp['User']['pswd'])>6) {           
            if ($this->User->save($this->data)) {
            $this->Session->setFlash('Data was Saved');         
                                                }
                                   }           
        } // this script works

And in the Model controller, I got these lines of codes:

  function beforeSave() {
     $raw = $this->data;
 if(strlen($raw['User']['pswd'])>6){
     md5($raw['User']['pswd']);        
 }
 return true;
                         } // this script failed to work

The data was stored into the Database successfully but it was not undergone any MD5 encryption.
I think that there must be some errors in the Model's script because I saw some errors
flashed after the data was saved, but the screen that showed the errors
immediately refreshed in a second after the data was saved successfully
and I couldn't see the detail of the errors that caused the problem.

Could you help me out please?

Edited:

I have altered the code of beforeSave, but it still fails to work:

function beforeSave() {
     $raw = $this->data;
 if(strlen($raw['User']['pswd'])>3){
     $raw['User']['pswd'] = md5($raw['User']['pswd']);      
 }
 return true;
                         }
+2  A: 

$raw is a local variable and hence doesn't exist outside of the beforeSave method. Depending on your use case you could simply override the value submitted by the user:

$this->data['User']['pswd'] = md5($raw['User']['pswd']);

dhofstet