[eluser]sasori[/eluser]
as the title says, I need logic help, i mean code snippet LOL
- when I don't put anything on the form and submit it,cool it shows the validation_errors();
- and then on the 2nd click its shows the flashdata
but when I input any random characters that doesn't exist on db, am being redirected to a blank page LOL
here's my controller code
Code:
public function forgot()
{
$data['main_content'] = 'forgot_view';
$data['title'] = 'Reset Password';
$this->load->view('includes/template',$data);
}
public function reset()
{
$this->form_validation->set_rules('username','Username','required');
if($this->form_validation->run() != FALSE)
{
$q = $this->member_model->getuser($this->input->post('username'));
if($this->input->post('username') == $q)
{
$this->member_model->reset($this->input->post('username'));
$this->session->set_flashdata('resetstat','You successfully reset your password');
$data['title'] = "Reset Password";
$data['main_content'] = 'new_password';
$this->load->view('includes/template',$data);
}
}
else
{
$this->session->set_flashdata('resetstat','its either we did not see your username in db or you typed it wrong');
$this->forgot();
}
}
here's my model code
Code:
public function getuser($user)
{
$this->db->where('username',$user);
$q = $this->db->get('user');
if($q->num_rows == 1)
{
return $q;
}
else
{
return FALSE;
}
}
public function reset($user)
{
$data = array('passwd'=> NULL);
$this->db->where('username',$user);
$q = $this->db->update('user',$data);
if($this->db->affected_rows() === 1)
{
return TRUE;
}
else
{
return FALSE;
}
}
and here's my view code
Code:
<h2>Reset password</h2><br />
<?php $session = $this->session->flashdata('resetstat');
if(isset($session)){ echo $session;} ?>
<?php echo validation_errors(); ?>
<?php echo form_open('user/reset'); ?>
<br />
<table cellpadding="0" cellspacing="2" bgcolor="#cccccc" width="250" >
<tr>
<td>Enter Your Username</td><td><?php echo form_input(array('name'=>'username','maxlength'=>'16','size'=>'16')); ?></td>
</tr>
<tr>
<td align="center" colspan="2"><?php echo form_submit('submit','change password'); ?></td>
</tr>
</table>
and here's the other view code
Code:
<h2>Reset password</h2><br />
<?php $session1 = $this->session->flashdata('resetstat');
$session2 = $this->session->flashdata('newpass');
if(isset($session)){ echo $this->session->flashdata('resetstat');}
if(isset($session)){ echo $this->session->flashdata('newpass');}
?>
<?php echo form_open('user/newpass'); ?>
<table cellpadding="0" cellspacing="2" bgcolor="#cccccc" width="250" >
<tr>
<td>New Password</td><td><?php echo form_password(array('name'=>'passwd','maxlength'=>'32','size'=>'16')); ?></td>
</tr>
<tr>
<td>Confirm Password</td><td><?php echo form_password(array('name'=>'passwd2','maxlength'=>'32','size'=>'16')); ?></td>
</tr>
<tr>
<td align="center" colspan="2"><?php echo form_submit('submit','change password'); ?></td>
</tr>
</table>
what should I do?