RalphLeMouf Posted October 15, 2012 Share Posted October 15, 2012 Ok - this seems like a duplicate but it's not because there was a glitch with my last question ( which I marked solved ) What's going on is that I have my errors working properly with all combinations of error in my form validation. However in the second to last elses ( which you'll see blank ) I can not figure what to put there to get the error message to display. When I enter a correct email and a gibberish password. It just reloads the form as it should, but with NO error message displayed. I've tried many things but am really stuck on this and need help ASAP. Here is what I'm working with: function validate_credentials_login() { $this->load->library('session'); $this->load->helper(array('form','url')); $this->load->model('user_model', 'um'); $this->load->library('encrypt'); $this->load->library('form_validation'); $this->form_validation->set_rules('email_login', 'Email', 'trim|required|valid_email'); $this->form_validation->set_rules('password_login', 'Password', 'trim|required'); if ( $this->form_validation->run() === TRUE ) { $user = $this->um->validate_home_login(array('email' => $this->input->post('email_login'))); if ( $user ) { 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'); } else { ?????? } } else { ????? } } $data['main_content'] = 'home/home_page'; $this->load->view('includes/templates/home_page_template', $data); } <?php echo form_open('auth/validate_credentials_login'); echo validation_errors('<div class="error">', '</div>'); echo form_label('', 'Email', 'email_login'); $data = array( 'name' => 'email_login', 'class' => 'input', 'placeholder' => 'Email'); echo form_input($data, set_value('email_login')); 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(); ?> everything else work great thanks so much in advance Quote Link to comment https://forums.phpfreaks.com/topic/269492-echoing-form-errors/ Share on other sites More sharing options...
RalphLeMouf Posted October 15, 2012 Author Share Posted October 15, 2012 another way of looking at it, is that it's doing it's job with that one combination I explained, but just not triggering the error message Quote Link to comment https://forums.phpfreaks.com/topic/269492-echoing-form-errors/#findComment-1385331 Share on other sites More sharing options...
Jessica Posted October 15, 2012 Share Posted October 15, 2012 Maybe you should put some stuff in your else blocks. Quote Link to comment https://forums.phpfreaks.com/topic/269492-echoing-form-errors/#findComment-1385333 Share on other sites More sharing options...
RalphLeMouf Posted October 15, 2012 Author Share Posted October 15, 2012 haha I know I have. What I'm saying is I can't figure out what to put in there. I've tried many things. Quote Link to comment https://forums.phpfreaks.com/topic/269492-echoing-form-errors/#findComment-1385334 Share on other sites More sharing options...
RalphLeMouf Posted October 15, 2012 Author Share Posted October 15, 2012 I've restructured my code structure as well MANY times and this is the closet so I'm keeping it, and trying to figure out how to echo the one error I'm missing Quote Link to comment https://forums.phpfreaks.com/topic/269492-echoing-form-errors/#findComment-1385335 Share on other sites More sharing options...
Jessica Posted October 15, 2012 Share Posted October 15, 2012 (edited) Are you using Code Igniter? You posted this in the Application Frameworks forum but didn't say what framework you're using. Did you look in the framework's documentation? Also, you should post what you tried, not just post "not triggering the error message". There IS no error message in any of your code. The closest thing is an empty div. "'<div class="error">', '</div>'" is not an error message. Finally, things like echo form_label('', 'Email', 'email_login'); Don't look quite right. Why do you have a blank first param? Edited October 15, 2012 by Jessica Quote Link to comment https://forums.phpfreaks.com/topic/269492-echoing-form-errors/#findComment-1385337 Share on other sites More sharing options...
RalphLeMouf Posted October 15, 2012 Author Share Posted October 15, 2012 I am using Code-Igniter. I left that blank because I don't want it to print a title. I've referenced the frameworks documentation A LOT. This just seems to be a triggering problem? Some of the things I've tried putting in those blank elses are: echo validation_errors(); or echo validation_error(); or those previous two with the field names in them. I've also tried echo "<div class='error'>"; echo validation_errors(); echo"</div>"; and $data['main_content'] = 'home/home_page'; $this->load->view('includes/templates/home_page_template', $data); which yields duplicate views I've also tried different code structures that loads duplicate views on my page as a result as well if ( $this->form_validation->run() === TRUE ) { $user = $this->um->validate_home_login(array('email' => $this->input->post('email_login'))); if ( $user ) { 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); } thanks for your time Quote Link to comment https://forums.phpfreaks.com/topic/269492-echoing-form-errors/#findComment-1385339 Share on other sites More sharing options...
RalphLeMouf Posted October 15, 2012 Author Share Posted October 15, 2012 I think this makes sense. Does it not? function validate_credentials_login() { $this->load->library('session'); $this->load->helper(array('form','url')); $this->load->model('user_model', 'um'); $this->load->library('encrypt'); $this->load->library('form_validation'); $this->form_validation->set_rules('email_login', 'Email', 'trim|required|valid_email'); $this->form_validation->set_rules('password_login', 'Password', 'trim|required'); if ( $this->form_validation->run() === TRUE ) { $user = $this->um->validate_home_login(array('email' => $this->input->post('email_login'))); if ( $user ) { 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'); } else { $this->form_validation->run() == FALSE; } } else { $this->form_validation->run() == FALSE; } } $data['main_content'] = 'home/home_page'; $this->load->view('includes/templates/home_page_template', $data); } Quote Link to comment https://forums.phpfreaks.com/topic/269492-echoing-form-errors/#findComment-1385359 Share on other sites More sharing options...
RalphLeMouf Posted October 15, 2012 Author Share Posted October 15, 2012 and in the view <?php echo form_open('auth/validate_credentials_login'); echo form_error('email_login'); echo form_label('', 'Email', 'email_login'); $data = array( 'name' => 'email_login', 'class' => 'input', 'placeholder' => 'Email'); echo form_input($data, set_value('email_login')); echo form_error('password_login'); 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(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/269492-echoing-form-errors/#findComment-1385364 Share on other sites More sharing options...
Scott_S Posted October 27, 2012 Share Posted October 27, 2012 Look at CI's Session Flashdata Quote Link to comment https://forums.phpfreaks.com/topic/269492-echoing-form-errors/#findComment-1388096 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.