Welcome Guest, Not a member yet? Register   Sign In
Issue with my 'Sign in' script
#7

[eluser]Bas Vermeulen[/eluser]
It's because you do a redirect, a whole new page request with no post data or form validation errors. If you really want to do a redirect you should set the form validation errors as flashdata before the redirect and check/display the flashdata in your view. I would prefer to just load the method of the comments view page (I guess that's in the same controller?):

Code:
function addcomment(){
  
      $this->load->library('form_validation');

      $this->form_validation->set_rules('post_id', 'post_id', 'required|numeric');
      $this->form_validation->set_rules('comment_body', 'Comments', 'trim|required');
  
      if($this->form_validation->run() == FALSE)
      {                
            $this->viewcomment($this->input->post('post_id')); // or w/e you called it ;)
      }
      else
      {  
            $this->MComments->addComment();
            $this->viewcomment($this->input->post('post_id'));
      }
  }

I also added a validation rule for the post_id, I think it's good practice to always validate all incoming postdata, even if it's a hidden input and you set the value's yourself. People can spoof forms and do bad things Smile


Also a little update in the view which I recently learned myself:
Code:
<?php if(!empty($this->form_validation->_error_array)):?>
    <div class="error">
        &lt;?php echo validation_errors(); ?&gt;  
    </div>  
&lt;?php endif; ?&gt;

The following works as well (shorter & cleaner):
Code:
&lt;?php if(validation_errors()):?&gt;
    <div class="error">
        &lt;?php echo validation_errors(); ?&gt;  
    </div>  
&lt;?php endif; ?&gt;

Good luck! Smile


Messages In This Thread
Issue with my 'Sign in' script - by El Forum - 10-05-2010, 12:29 PM
Issue with my 'Sign in' script - by El Forum - 10-05-2010, 01:26 PM
Issue with my 'Sign in' script - by El Forum - 10-05-2010, 01:58 PM
Issue with my 'Sign in' script - by El Forum - 10-05-2010, 02:07 PM
Issue with my 'Sign in' script - by El Forum - 10-05-2010, 02:13 PM
Issue with my 'Sign in' script - by El Forum - 10-05-2010, 02:32 PM
Issue with my 'Sign in' script - by El Forum - 10-05-2010, 02:44 PM
Issue with my 'Sign in' script - by El Forum - 10-05-2010, 02:53 PM
Issue with my 'Sign in' script - by El Forum - 10-05-2010, 02:56 PM
Issue with my 'Sign in' script - by El Forum - 10-05-2010, 03:02 PM
Issue with my 'Sign in' script - by El Forum - 10-05-2010, 03:04 PM
Issue with my 'Sign in' script - by El Forum - 10-05-2010, 03:15 PM
Issue with my 'Sign in' script - by El Forum - 10-05-2010, 03:17 PM
Issue with my 'Sign in' script - by El Forum - 10-06-2010, 07:25 AM



Theme © iAndrew 2016 - Forum software by © MyBB