Jump to content

Echoing Form Errors


RalphLeMouf

Recommended Posts

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

Link to comment
Share on other sites

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 by Jessica
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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);   

   } 

Link to comment
Share on other sites

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();
?>

Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.