[eluser]selman555[/eluser]
Hi, I'm trying to notify the user about the status of his request.
It's a simple profile page where he can change his email of password.
When the controller method is done, I want to load the same view with $data containing messages.
But the view is loaded a second time at the bottom of my first view.
I can't seem to get the layout right, it's basically two forms with actions user/changePassword and user/changeEmail
Here's the view:
Code:
<!DOCTYPE html />
<html lang="nl-be">
<head>
<link rel="stylesheet" href="<?php echo base_url('styles/main.css'); ?>" />
<link rel="stylesheet" href="<?php echo base_url('styles/profile.css'); ?>" />
<title>Profile</title>
</head>
<body>
<?php include 'templates/header.php'; ?>
<section id="profilepage" 0 2%">
<h1><?php echo $this->lang->line('profileTitle');?></h1>
<?php if ($this->session->userdata('logged_in')) {?>
<form id="submitnewemail" acti method="post">
<table>
<caption><?php echo $this->lang->line('email');?></caption>
<tbody>
<tr>
<th>E-mail</th>
<td colspan="3"><?php echo $this->session->userdata('email');?></td>
</tr>
<tr>
<th><?php echo $this->lang->line('reset');?></th>
<td><input name="email" type="email" placeholder="<?php echo $this->lang->line('new');?>" class="tekstfield"
id="email" required ></td>
<td><input name="emailconfirm" type="email" placeholder="<?php echo $this->lang->line('confirm');?>" class="tekstfield" id="emailconfirm"required ></td>
<td><input type="submit" value="<?php echo $this->lang->line('paswoordbtnReset');?>" id="resetemail" /></td>
</tr>
<?php if (isset($errorsMail)) {?>
<tr id="error"><td colspan="4" right;"><?php echo $errorsMail; ?></td></tr>
<?php }
if (isset($doneMail)) {?>
<tr><td colspan="4" right;"><?php echo $doneMail; ?></td></tr>
<?php } ?>
</tbody>
</table>
</form>
<form id="submitnewpassword" acti method="post" >
<table 100%">
<caption><?php echo $this->lang->line('passwordresettitle');?></caption>
<tbody>
<tr>
<th><?php echo $this->lang->line('reset');?></th>
<td><input id="newpass" name="newpass" type="password" placeholder="<?php echo $this->lang->line('new');?>" class="tekstfield" required >
<td><input id="confirmpass" name="confirmpass" type="password" placeholder="<?php echo $this->lang->line('confirm');?>" class="tekstfield" required >
</tr>
<tr>
<th><?php echo $this->lang->line('passwordOld');?></th>
<td><input id="oldpass" name="oldpass" type="password" placeholder="<?php echo $this->lang->line('loginPassword');?>" class="tekstfield" required >
<td><input type="submit" value="<?php echo $this->lang->line('paswoordbtnReset');?>" id="resetpass" /></td>
</tr>
<?php if (isset($errorsPass)) {?>
<tr id="error"><td colspan="3" right;"><?php echo $errorsPass; ?></td></tr>
<?php }
if (isset($donePass)) {?>
<tr><td colspan="4" right;"><?php echo "done"; ?></td></tr>
<?php } ?>
</tbody>
<table>
</form>
<?php } else { ?>
<?php echo $this->lang->line('loginMeldingIngelogd');?><br />
<?php echo $this->lang->line('loginMeldingNietIngelogd');?> <a href="<?php echo base_url('user/logout'); ?>"><?php echo $this->lang->line('loginMeldingNietIngelogd2');?></a>
<?php }?>
</section>
<?php include 'templates/footer.php'; ?>
</body>
</html>
And as an example, the changePassword method:
Code:
public function changePassword() {
$this->form_validation->set_rules('oldpass', 'newPass','trim|required|xss_clean');
$this->form_validation->set_rules('newpass', 'oldPass','trim|required|xss_clean');
$this->form_validation->set_rules('confirmpass', 'confirmPass','trim|required|xss_clean');
if($this->form_validation->run()){
$oldPass = $this->input->post('oldpass');
$newPass = $this->input->post('newpass');
$confirmPass = $this->input->post('confirmpass');
$username = $this->session->userdata('username');
$salts = $this->user_model->getSalt($username);
$salt = "";
foreach ($salts as $onlySalt) {
$salt = $onlySalt->Mem_Salt;
}
if($salt && $username) {
$boolean = $this->user_model->login($username,$oldPass,$salt);
if($boolean) {
$this->user_model->updatePassword($username,$newPass,$salt);
$data['donePass'] = "Uw paswoord is veranderd.";
} else {
$data['errorsPass'] = "Uw paswoord was niet correct.";
}
} else {
$data['errorsPass'] = "U kon niet worden geauthoriseerd.";
}
} else {
$data['errorsPass'] = "Gelieve alle velden met een geldige waarde in te vullen.";
}
$this->load->view('profile',$data); //How do I do this?
}
So after submitting the form, I load the same view again, but it just duplicates underneath with the $data value in place.
I added an image to illustrate.
Any help is welcome.