Welcome Guest, Not a member yet? Register   Sign In
Username And Email Login Form Validation Question
#1

(This post was last modified: 04-12-2017, 08:29 PM by wolfgang1983.)

I have one input field called type where the user can enter his/her email or username

Code:
<div class="form-group">
<label>Username Or Email</label>
<?php echo form_input('type', $type, array('class' => 'form-control'));?>
</div>

On my form validation rules check I have this 


Code:
$this->form_validation->set_rules('type', 'Username Or Email', 'trim|required'); 


But because the type input can be username or email can not use valid_email I have this 


Code:
$this->form_validation->set_rules('type', 'Username Or Email', 'trim|required|valid_email'); 


QUESTION: How can I check if the user enters email that it can check is valid_email but if the user enters username will not need to check valid_email do I need to do a separate callback? 


Code:
public function validateForm() {
$input_type = $this->input->post('type',  true);
$input_password = $this->input->post('password', true);

$stored_hash = $this->user_model->get_password($input_type);

$this->form_validation->set_rules('type', 'Username Or Email', 'trim|required');
$this->form_validation->set_rules('password', 'password', 'trim|required');

if (!$this->form_validation->run()) {

if (form_error('type')) {
$this->error['type'] = form_error('type');
}

if (form_error('password')) {
$this->error['password'] = form_error('password');
}

}

if (!empty($input_password) && !password_verify($input_password, $stored_hash)) {
$this->error['warning'] = 'Opp\'s username and or password incorrect!';
}

return !$this->error;
}


Attached Files
.php   Login.php (Size: 2.4 KB / Downloads: 110)
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply


Messages In This Thread
Username And Email Login Form Validation Question - by wolfgang1983 - 04-12-2017, 08:22 PM



Theme © iAndrew 2016 - Forum software by © MyBB