Follow-up:
Got it worked.
On Jul 6, 9:51 am, Steveston <[EMAIL PROTECTED]> wrote:
> Hi folks,
>
> I want to edit user's profile and save changes. It is supposed not to
> be a hard task, however, I do not know why I cannot make it work. Any
> help? Many thanks!
>
> the method in controller is:
>
> function editProfile()
> {
> $id = $this->rdAuth->id;
> $ifChangePassword=false;
> $ifPasswordError=false;
>
> $id = $this->Sanitize->paranoid($id); //Clear $id to only the
> alphanumeric value
>
> if (empty($this->params['data']))
> {
> $this->User->setId($id);
> $this->data = $this->User->read(); //load current user's
> data & pre-fill view page
> } //end of if form is empty
>
> else //not empty form
> {
> //if password1 and password2 are not empty
> if (!empty($this->params['form']['password1']) && !
> empty($this->params['form']['password2']) )
> {
>
> if ($this->params['form']['password1'] ==
> $this->params['form']['password2'] )
>
> $ifChangePassword=true;
> else
> $ifPasswordError=true;
> }
> //else: both empty, ifPasswordError and ifChangePassword
> are both false, default value
> if ($ifChangePassword && !$ifPasswordError )
> $this->data['User']['password']=$this->params['form']
> ['password1'];//update password
> if ( $this->User->save($this->data))
> {
> //Render to view page to display saved data
> //TODO: Display list of users after import
> $user = $this->User->read();
> $this->set('data', $user);
> }
> else
> $this->validateErrors($this->User);
> }
>
> $this->set('ifChangePassword',$ifChangePassword);
> $this->set('ifPasswordError',$ifPasswordError);
> $this->set('passwordError','Password inputs do not match');
> $this->User->save($this->data);
> echo $ifChangePassword ? 'ifChangePassword=>yes
> ':'ifChangePassword=no ';
> echo $ifPasswordError ? 'ifPasswordError=>yes
> ':'ifPasswordError=>no';
> }
>
> Its view page is:
>
> <p align="center">Edit Profile </p>
> <?php
> echo $html->formTag('/users/editProfile');
> echo empty($data['User']['id']) ? null : $html->hidden('User/
> id',array('value'=>$data['User']['id']));
> echo empty($data['User']['role']) ? null: $html->hidden('User/
> role',array('value'=>$data['User']['role']));
> ?>
> <table width="100%" border="0">
> <tr>
> <td width="15%">Username</td>
> <td width="85%"><?php echo $html->input('User/username',array
>
> ("size"=>15,'disabled'=>true));
> echo $html->tagErrorMsg('User/username','Username error'); ?></td>
> </tr>
> <tr>
> <td>Last Name </td>
> <td><?php echo $html->input("User/last_name",array("size"=>15));
> echo '<b>'.$html->tagErrorMsg('User/last_name','Last name cannot
> contain
>
> number').'</b>'; ?></td>
> </tr>
> <tr>
> <td>First Name </td>
> <td><?php echo $html->input("User/first_name",array("size"=>15));
> echo '<b>'.$html->tagErrorMsg('User/firstname','First name cannot
> contain
>
> number').'</b>'; ?></td>
> </tr>
> <tr>
> <td>Title</td>
> <td><?php echo $html->input("User/title",array("size"=>15)); ?></
> td>
> </tr>
> <tr>
> <td>Student Number </td>
> <td><?php
> echo $html->input("User/student_no",array("size"=>15));
> ?></td>
> </tr>
>
> <tr>
> <td>Email</td>
> <td><?php echo $html->input("User/email",array("size"=>30));
> echo '<b>'.$html->tagErrorMsg('User/email','Invliad Email
> format').'</b>'; ?></td>
> </tr>
> <tr>
> <td>New password </td>
> <td> Please leave the following two input fields empty if you do
> not want to change password <br/><input type="password"
> name="password1"/>
> <?php
> if (isset($ifPasswordError) && $ifPasswordError)
> echo '<b>'.$passwordError.'</b>';
> ?>
> </td>
> </tr>
> <tr>
> <td>Confirm your password </td>
> <td> <input type="password" name="password2"/> </td>
> </tr>
>
> </table>
> <center>
> <?php
> echo $html->submit('Submit');
> ?> </center>
> </form>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---