Welcome Guest, Not a member yet? Register   Sign In
Trying to send a message back to my view after posting a form
#1

[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 />
&lt;html lang="nl-be"&gt;
&lt;head&gt;
  &lt;link rel="stylesheet" href="&lt;?php echo base_url('styles/main.css'); ?&gt;" /&gt;
                &lt;link rel="stylesheet" href="&lt;?php echo base_url('styles/profile.css'); ?&gt;" /&gt;
  &lt;title&gt;Profile&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
  &lt;?php include 'templates/header.php'; ?&gt;

  <section id="profilepage"  0 2%">
             <h1>&lt;?php echo $this->lang->line('profileTitle');?&gt;</h1>
             &lt;?php if ($this->session->userdata('logged_in')) {?&gt;
             &lt;form id="submitnewemail" acti method="post"&gt;
              <table>
    <caption>&lt;?php echo $this->lang->line('email');?&gt;</caption>
    <tbody>
    <tr>
         <th>E-mail</th>
     <td colspan="3">&lt;?php echo $this->session->userdata('email');?&gt;</td>
    </tr>
    <tr>
     <th>&lt;?php echo $this->lang->line('reset');?&gt;</th>
     <td>&lt;input name="email" type="email" placeholder="&lt;?php echo $this-&gt;lang-&gt;line('new');?&gt;" class="tekstfield"
              id="email" required &gt;&lt;/td>
                   <td>&lt;input name="emailconfirm" type="email" placeholder="&lt;?php echo $this-&gt;lang-&gt;line('confirm');?&gt;" class="tekstfield"                      id="emailconfirm"required  &gt;&lt;/td>
                   <td>&lt;input type="submit" value="&lt;?php echo $this-&gt;lang-&gt;line('paswoordbtnReset');?&gt;" id="resetemail" /&gt;&lt;/td>
    </tr>
    &lt;?php if (isset($errorsMail)) {?&gt;
    <tr id="error"><td colspan="4"  right;">&lt;?php echo $errorsMail; ?&gt;</td></tr>
    &lt;?php }
       if (isset($doneMail)) {?&gt;
    <tr><td colspan="4"  right;">&lt;?php echo $doneMail; ?&gt;</td></tr>
    &lt;?php } ?&gt;
   </tbody>
  </table>
  &lt;/form&gt;
                &lt;form id="submitnewpassword" acti method="post" &gt;
              <table  100%">
    <caption>&lt;?php echo $this->lang->line('passwordresettitle');?&gt;</caption>
    <tbody>
     <tr>
     <th>&lt;?php echo $this->lang->line('reset');?&gt;</th>
     <td>&lt;input id="newpass" name="newpass" type="password" placeholder="&lt;?php echo $this-&gt;lang-&gt;line('new');?&gt;" class="tekstfield" required &gt;
                   <td>&lt;input id="confirmpass" name="confirmpass" type="password" placeholder="&lt;?php echo $this-&gt;lang-&gt;line('confirm');?&gt;" class="tekstfield"                     required  &gt;
     </tr>
     <tr>
             <th>&lt;?php echo $this->lang->line('passwordOld');?&gt;</th>
      <td>&lt;input id="oldpass" name="oldpass" type="password" placeholder="&lt;?php echo $this-&gt;lang-&gt;line('loginPassword');?&gt;" class="tekstfield" required &gt;
                    <td>&lt;input type="submit" value="&lt;?php echo $this-&gt;lang-&gt;line('paswoordbtnReset');?&gt;" id="resetpass" /&gt;&lt;/td>
     </tr>
     &lt;?php if (isset($errorsPass)) {?&gt;
     <tr id="error"><td colspan="3"  right;">&lt;?php echo $errorsPass; ?&gt;</td></tr>
     &lt;?php }
         if (isset($donePass)) {?&gt;
     <tr><td colspan="4"  right;">&lt;?php echo "done"; ?&gt;</td></tr>
     &lt;?php } ?&gt;
    </tbody>
   <table>
  &lt;/form&gt;
                &lt;?php } else { ?&gt;
                &lt;?php echo $this->lang->line('loginMeldingIngelogd');?&gt;<br />
                &lt;?php echo $this->lang->line('loginMeldingNietIngelogd');?&gt; <a href="&lt;?php echo base_url('user/logout'); ?&gt;">&lt;?php echo $this->lang->line('loginMeldingNietIngelogd2');?&gt;</a>
                &lt;?php }?&gt;
        </section>

  &lt;?php include 'templates/footer.php'; ?&gt;
&lt;/body&gt;
&lt;/html&gt;

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.
#2

[eluser]selman555[/eluser]
Never mind.
I found the problem Wink
I loaded the view in my model too :/




Theme © iAndrew 2016 - Forum software by © MyBB