RalphLeMouf Posted October 10, 2012 Share Posted October 10, 2012 Hey guys! I know I've asked a couple of different questions in this matter, but this is getting to the point of sheer frustration. I've gathered many resources to check against my logic and syntax - mainly the code igniter user guide and tips and suggestions I've gathered on this forum. I have restructured to where it makes the most logical sense to me, and for some reason the validation errors for my login are still acting screwy. Here is what I have with comments on my logic: I'm still getting white pages with some combinations. Everyone has said because there are extra "elses" that I am leaving blank, however I am confused on what to put there because I feel like my bases of all the criteria are already covered. What am I missing? function validate_credentials_login() { // LOAD THE SESSION LIBRARY $this->load->library('session'); // LOAD THE URL AND FORM HELPERS $this->load->helper(array('form','url')); // LOAD THE RELEVENT MODEL AND SET A NAME FOR IT $this->load->model('user_model', 'um'); // LOAD ENCRYTPION LIBRARY IN ORDER TO ENCRYPT PASSWORDS PROPERLY $this->load->library('encrypt'); // LOAD THE FORM VALIDATION LIBARARY TO MAKE USE OF ERROR HANDLING $this->load->library('form_validation'); // SET RULES FOR MY EMAIL FIELD $this->form_validation->set_rules('email_login', 'Email', 'trim|required'); // SET RULES FOR MY PASSWORD FIELD $this->form_validation->set_rules('password_login', 'Password', 'trim|required'); // MAKE A VARIABLE FOR MY SUBMIT BUTTON $login = $this->input->post('submit_login'); // IF THE SUBMIT BUTTON IS SET if($login) { // MAKE THIS VARIABLE THAT CHECKS THE EMAIL FEILD INSERTED VIA POST AGAINST THE ONE STORED IN MY DATABASE $user = $this->um->validate_home_login(array('email' => $this->input->post('email_login'))); // IF THIS USER EXISTS AND THERE ARE NO ERRORS SET OFF BY THE FORM VALIDATION CHECK if($user && $this->form_validation->run()) { // DO THIS STUFF AKA IF THE USERS PASSWORD IS THE SAME AS THE ONE INSERTED VIA POST AND THE USERS EMAIL IS THE SAME INSERTED VIA POST EVERYTHING IS GOOD AND YOU CAN LOG THEM IN AND START A SESSION if($user->password == $this->encrypt->sha1( $user->salt . $this->encrypt->sha1($this->input->post('password_login'))) && $user->email == $this->input->post('email_login')) { $this->session->set_userdata(array( 'email' => $this->input->post('email_login') )); redirect('account/edit'); } $data['main_content'] = 'home/home_page'; $this->load->view('includes/templates/home_page_template', $data); } // IF ANYTHING IS OFF OR DOESN'T MATCH ( SUPOSEDELY ) RUN THE FORM VALIDATION AS FALSE AND RELAOD THE PAGE WITH ERRORS elseif($this->form_validation->run() == FALSE) { $data['main_content'] = 'home/home_page'; $this->load->view('includes/templates/home_page_template', $data); } } } function create_member() { $this->load->library('form_validation'); $this->form_validation->set_rules('first_name', 'First Name', 'trim|required'); $this->form_validation->set_rules('last_name', 'Last Name', 'trim|required'); $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email'); $this->form_validation->set_rules('password', 'Password', 'trim|required'); $this->form_validation->set_rules('password2', 'Confirm Password', 'trim|required|matches[password]'); if($this->form_validation->run() == FALSE) { $data['main_content'] = 'home/home_page'; $this->load->view('includes/templates/home_page_template', $data); } else { $this->load->model('user_model'); if($query = $this->user_model->create_member()) { $this->load->model('user_model'); $this->varification_email(); $data['main_content'] = 'account/welcome'; $this->load->view('includes/templates/main_page_template', $data); } else { $this->load->view('home/home_page'); } } } <?php echo form_open('auth/validate_credentials_login'); echo "<span class='errors_login'>"; echo form_error('email_login'); echo "</span>"; echo form_label('', 'Email', 'email_login'); $data = array( 'name' => 'email_login', 'class' => 'input', 'placeholder' => 'Email'); echo form_input($data, set_value('email_login')); echo "<span class='errors_login'>"; echo form_error('password_login'); echo "</span>"; echo form_label('', 'Password;', 'password_login'); $data = array( 'name' => 'password_login', 'class' => 'input', 'placeholder' => 'Password'); echo form_password($data, set_value('sha1(password_login)')); echo form_submit('submit_login', 'Login'); echo form_close(); ?> function validate_home_login($data) { // TAKING THE DATA FROM THE MODEL AND CHECKING IT AGAINST THE STORED INFO IN THE DB $query = $this->db->where($data)->get('users', '1'); if($query->row()) { return $query->row(); } } Quote Link to comment https://forums.phpfreaks.com/topic/269327-form-validation-errors-issues/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.